localize-router icon indicating copy to clipboard operation
localize-router copied to clipboard

Component reuse after language change

Open acopapic opened this issue 6 years ago • 8 comments

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

acopapic avatar Nov 06 '18 14:11 acopapic

Take a look at last messages on https://github.com/Greentube/localize-router/issues/140

gilsdav avatar Nov 07 '18 12:11 gilsdav

@gilsdav Thanks for your feedback. I just tried it with your gilsdav/ngx-translate-router and it seems to work. Perfect!

acopapic avatar Nov 07 '18 12:11 acopapic

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 avatar Nov 07 '18 13:11 acopapic

@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 avatar Nov 07 '18 13:11 meeroslav

@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 avatar Nov 07 '18 14:11 acopapic

@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

gilsdav avatar Nov 08 '18 07:11 gilsdav

@meeroslav Any update of Version 2 milestone?

acopapic avatar Dec 16 '18 23:12 acopapic

@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'

image

acopapic avatar Jan 09 '19 15:01 acopapic