0

I have some routes in my app.module.ts :

 {path: 'infos/:lang', loadChildren: './base-infos/base-infos.module#BaseInfosModule' },
  {path: '', redirectTo: 'infos/fr', pathMatch: 'full' }

And iam calling the first route in my code :

this._router.navigate(['infos/', this.currentLang ])

If i choose the language english, so "this.currentLang" equals to "en" in the url "infos/en". The issue is, even if i choose "en" it always leads me to "infos/fr" instead of "infos/en".

Is there any reason why my code is doing this ??? thanks

1
  • whats if you hard code this._router.navigate(['infos','en']). Does it still go to the fr route? I am betting it won't, which means that someone is setting this.currentLang to fr. Commented Nov 30, 2018 at 22:33

2 Answers 2

2

for first try place the route with path: '' above the another route, like that:

{path: '', redirectTo: 'infos/fr', pathMatch: 'full' }, 
{path: 'infos/:lang', loadChildren: './base-infos/base-infos.module#BaseInfosModule' }

or also try this router.navigate function:

this._router.navigate([`infos/${ this.currentLang }`]);

or also you can try it without the / symbol:

this._router.navigate(['infos', this.currentLang ]);
Sign up to request clarification or add additional context in comments.

Comments

1

You don't need trailing '/' in navigate call. Try below line

this._router.navigate(['infos', this.currentLang ])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.