On my angular app I have only one route with a parameter (a language parameter):
{
path: ":lang",
component: MainContentComponent,
}
In my app, I navigate to the same route with a different language parameter whenever the user wants to switch the language with:
this.router.navigate(["en"]);
This concept works so far, but I have one problem with it: When navigating back with the browser "Go backwards one page" button, the URL gets updated but the component is not reloaded with the new language, i.e. no rerouting is triggered.
What is the reason for that?
Is there some simple option of the router which could change this behavior? Or do I need to programmaticly listen for the event (with @HostListener('window:popstate', ['$event'])) and reload manually?
Subscribe to ActivatedRoute Params Instead of using @HostListener to listen for popstate events, a more Angular-centric way to address this issue is to subscribe to the route parameters in your component and react to changes in the parameters. You can do this using the ActivatedRoute service provided by Angular's Router package.