I am working with Angular 7 and changing the URL parameter does not update the content because it does not reload the constructor or the ngOnInit, all URLs call the same components for example CategoryComponent but depending on the URL parameter it shows some products or others.
I explain it better with code.
Router component.
const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: ':category', component: CategoryComponent },
{ path: '**', component: Error404Component }
];
I have a menu with a dropdown-menu
<div class="dropdown-menu" aria-labelledby="dropdownMenuCategory">
<a class="dropdown-item" [routerLink]="['/robots-aspiradores']">Robots Aspiradores</a>
<a class="dropdown-item" [routerLink]="['/patinetes-electricos']">Patinetes Eléctricos</a>
<a class="dropdown-item" [routerLink]="['/cafeteras']">Cafeteras</a>
</div>
CategoryComponent Constructor
constructor( private _activatedRoute: ActivatedRoute, private _productService: ProductService ) {
this.url = GLOBAL.url;
this.categoryName = this._activatedRoute.snapshot.paramMap.get("category")
this.getProductsCategory(this.categoryName);
this.title = this.categoryName.replace('-', ' ').toUpperCase();
}
I want that when each menu option is clicked, the constructor or ngOnInit reloads, but it only loads the first time I enter, but if I move from one category page to another, it does not reload, I have to go to HOME and enter to another category to reload.
I don't know if I explained myself well, I hope so, greetings and thanks.