This repository has been archived by the owner on May 31, 2024. It is now read-only.
Styling the navigation links based on active route #469
ajmchambers
started this conversation in
General
Replies: 1 comment
-
I think the window.addEventListener('vaadin-router-location-changed', (event) => {
const { route } = event.detail.location;
// And now you use the `route.name`!
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think it would be good to include an example of styling the active navigation links based on the current route as this probably a pretty common ask, its basically one of the first things I tried to get working and the right approach is not immediately obvious.
To be complete it would be good to have an example of styling a link that has child routes e.g.
if the link was to
/items
which displayed a list of items.Then navigating to
/items/item1
should still consider the link as active as it is a child route of items.Not sure how best to do this, seems vaadin router passes route information down to the routed elements, e.g.
location.params.id
.However since the navigation links are in
app-index.ts
where the router itself is attached it won't have access to that .So one option would be to move the navigation links into one of the routed components (maybe an overall parent layout component that matches all routes, which handles the navigation bar itself with a slot for the content - then have child routes to '/' and '/about' for the home and about content.
Or another option would be to add an event listener in the
app-index.ts
that updates some state containing the current routing information (bit like this: vaadin/router#483).Maybe there is a better way, any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions