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

Wrong root route redirectTo value after changing language in the URL #122

Open
JakubNiedzialkowski opened this issue Apr 25, 2022 · 0 comments

Comments

@JakubNiedzialkowski
Copy link

Description

After changing language code in the URL the root route's redirectTo value is set incorrectly to the previously used value. This results in problems with triggering router.navigate(['/'])

The actual value of the route object:

{ path: "", redirectTo: "fr", pathMatch: "full" }

Desired value of the route object after changing language in the URL:

{ path: "", redirectTo: "en", pathMatch: "full" }

Reproducing the issue

I used the demo app included on the master branch to reproduce the issue. Inside app.component.ts I added a simple console.log() printing out router config like:

    constructor(private localize: LocalizeRouterService, private router: Router) { }

    ngOnInit() {
      console.log(this.router.config);
      (...)
     }

Steps to reproduce

  1. Set up the demo app included in project's master branch
  2. Launch the app
  3. In browser address bar change language code from /en/ -> /fr/ or /fr/ -> /en/
    reditrectToRootBug

Possible solution

I believe the issue is caused by the following piece of code inside localize-router.parser.ts:

   if (this.settings.alwaysSetPrefix) {
      const baseRoute = { path: '', redirectTo: this.defaultLang, pathMatch: 'full' };
      (...)

Since this.defaultLang doesn't take locationLang into consideration. The likely solution would be to change this bit of code to:

const baseRoute = { path: '', redirectTo: selectedLanguage, pathMatch: 'full' };

I'd appreciate any feedback in case I got something wrong in this whole testing problem :)

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

No branches or pull requests

1 participant