localize-router
localize-router copied to clipboard
Component reuse after language change
Hi there,
I tried the latest version of the localize-router (2.0.0-RC.1) with Angular 6 and Angular 7 but it seems that now localize-router changeLanguage() recreates component every time, i.e. it treat the language change as a completely new route. What do I do wrong here? With previous version (Angular 5.1.3 and localize-router 1.0.0-rc.4) it worked as I expected, with component reuse.
Thanks and regards, Aleksandar
Take a look at last messages on https://github.com/Greentube/localize-router/issues/140
@gilsdav Thanks for your feedback. I just tried it with your gilsdav/ngx-translate-router and it seems to work. Perfect!
Actually it strips query parameters from the url. And the behavior with the browser's back button is strange - it always returns me to the first page where I started from.
@acopapic,
Due to implementation changes in the router, routes are no longer mutable and therefore after language change we have to reset the routes. This has a side effect that routes are by default not reused.
@gilsdav solved it nicely in his ngx-translate-router
fork, but this repo is now behind localize-router with fixes, so my suggestion is following:
- copy reuse strategy
- wait few days until this is integrated into localize-router
@meeroslav
I guess I will wait a few days because copying reuse strategy solved some of the problems but I still have a problem with browser's back button after changing the language. It crashes with the message: 'Cannot match any routes.'
Regards
@acopapic I'm not sure to understand your problem with browser back.
- If it's '/en/home' --navigate--> '/en/blog' --changeLang--> 'fr/blog' --back--> '/en/blog' --back--> '/en/home', this is because the urls in history states contains lang.
- If your problem is not previous point, check if it's not a guard that do it.
Keep in mind that component will not be recreated using ReuseStrategy but your guards will be called on every url changes
@meeroslav Any update of Version 2 milestone?
@gilsdav Sorry for the very late reply. My problem is the following: 'en-ch/search/ --navigate--> 'en/search?par1=val1&par2=val2' --changeLang--> 'de-ch/suchen?par1=val1&par2=val2' --browserBack--> Error: Uncaught (in promise): Error: Cannot match any routes. Url Segment: 'de-ch/suchen'