T
TanStack17mo ago
stormy-gold

Styling parent of <Link> with active state

I'd like to style a navigation that's structured like this:
<ul>
<li className="active">
<Link to="/foo">...</Link>
</li>
</ul>
<ul>
<li className="active">
<Link to="/foo">...</Link>
</li>
</ul>
How do i elegantly control the className? I was looking at comparing /foo withuseLocation().pathname but it's typed as string so maybe there's a better way.
4 Replies
stormy-gold
stormy-goldOP17mo ago
AFAIK the HTML spec does not allow changing the hierarchy to have ul, then a (Link), then li.
multiple-amethyst
multiple-amethyst17mo ago
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
multiple-amethyst
multiple-amethyst17mo ago
checkout the /about page
No description
stormy-gold
stormy-goldOP16mo ago
@Manuel Schiller thank you! createLink is what i was missing

Did you find this page helpful?