Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component reuse after language change #146

Open
acopapic opened this issue Nov 6, 2018 · 8 comments
Open

Component reuse after language change #146

acopapic opened this issue Nov 6, 2018 · 8 comments

Comments

@acopapic
Copy link

acopapic commented Nov 6, 2018

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

@gilsdav
Copy link

gilsdav commented Nov 7, 2018

Take a look at last messages on #140

@acopapic
Copy link
Author

acopapic commented Nov 7, 2018

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

@acopapic
Copy link
Author

acopapic commented Nov 7, 2018

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.

@meeroslav
Copy link
Collaborator

@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 meeroslav added this to the Version 2 milestone Nov 7, 2018
@acopapic
Copy link
Author

acopapic commented Nov 7, 2018

@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

@gilsdav
Copy link

gilsdav commented Nov 8, 2018

@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

@acopapic
Copy link
Author

@meeroslav Any update of Version 2 milestone?

@acopapic
Copy link
Author

acopapic commented Jan 9, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants