I need assistance with managing routes
const routes: Routes = [
{ path: 'home', component: HomeComponent },
{
path: 'explore',
component: ExploreComponent,
children: [
{ path: '', component: ProductListComponent },
{ path: ':categorySlug', component: ProductListComponent }
]
}
];
This setup allows users to visit
/explore
(without a specific category)
or
/explore/computers
(with the category computers
)
My goal is to be able to listen for changes in the categorySlug
parameter from the parent (ExploreComponent
) and handle those changes accordingly. How can this be achieved?
EDIT:
I attempted to subscribe using:
this.activatedRoute.firstChild.params.subscribe(console.log);
While it provides the desired outcome, it stops functioning when navigating to /explore
(no specific category). It only works when using links like /explore/:categorySlug
.