Sidenav does not set 'active' on current route, does not support routerLinkActive
See original GitHub issueWhen you select a link in MaterializeCss’s sidenav, the link is set to active. The ng2-materialize sidenav doesn’t automatically set the class for a newly selected link and doesn’t appear to expose any way for the developer to do so. The standard way to do that in angular is to set the class for the item with routerLinkActive="['className']"
.
Proposal: replace <li [class.active]="active">
with <li [routerLinkActive]="['active']">
in sidenav-link.component.html and add the import for angular/router
to the app module.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
In Angular, how do you determine the active route?
I've been trying to set the active class without having to know exactly what's the current location (using the route name). The is...
Read more >RouterLinkActive - Angular
Tracks whether the linked route of an element is currently active, and allows you to specify one or more CSS classes to add...
Read more >Side Nav - Page Reload - Auto Expand with route parameters o
When reloading the page, if the current route has route parameters then the sub-menu mdb-accordion-item should auto expand. Actual behavior.
Read more >Styling Active Router Link in Angular - GeeksforGeeks
Here we have provided the “routerLinkActive” which is routing functionality that automatically activate the current route, and we have to ...
Read more >Add an active className to the link using React Router
2. useLocation Hook. React router has a hook which can be very useful to know the current route. The above method of using...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It looks like we’ll be good to go, with the PR suggested at Materialize. https://github.com/Dogfalo/materialize/pull/5285 It will allow
.active
to apply to any element instead ofli
ora
. Then this:will work as expected.
In case anyone else experiences this issue, the workaround I used was to fill the list item with the anchor and set the class on the anchor. This doesn’t hit all use cases, but it does work as expected. Example: