I am currently working on implementing a navigation feature in an Angular application. I want to be able to access the same page from different "parent" pages while maintaining the navigation bar's awareness of the origin page.
For navigation, I am utilizing routerLinkActive="active"
. In my application, I have two pages, "Favorites" and "All users," both displaying lists of users. Each user has a details page accessible through users/userId
.
My goal is to ensure that when a user navigates to the details page from the "Favorites" list, the "Favorites" menu button remains active in the navigation bar. Similarly, when navigating from the "All users" list, the "All users" button should stay active.
Here is how my routes are currently set up:
const routes: Routes = [
{
path: 'favorites',
component: FavoritesComponent
},
{
path: 'all',
component: AllUsersComponent
},
{
path: 'user/:id',
component: UserDetailComponent,
}
Currently, when navigating to the user/id
page, neither "favorites" nor "all" remains "active" in the navigation bar as intended.