T
TanStack14mo ago
sensitive-blue

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
sensitive-blue
sensitive-blueOP14mo ago
AFAIK the HTML spec does not allow changing the hierarchy to have ul, then a (Link), then li.
equal-aqua
equal-aqua14mo ago
StackBlitz
Router Quickstart File Based Example (forked) - StackBlitz
Run official live example code for Router Quickstart File Based, created by Tanstack on StackBlitz
equal-aqua
equal-aqua14mo ago
checkout the /about page
No description
sensitive-blue
sensitive-blueOP14mo ago
@Manuel Schiller thank you! createLink is what i was missing

Did you find this page helpful?