When changing language the route is appending to instead of just changing with chosen language

601 Views Asked by At

When I am changing the language the route gets appended to previous routes instead of just changing the language for exe- http://localhost:4200/en/about-us if change the language to he then it becomes http://localhost:4200/he/about-us/about-us I am changing the language like this.

constructor(
    public translate: TranslateService,
    private localize: LocalizeRouterService
){}
chooseLanguage('he') { 
        this.translate.use(lng);
        this.localize.changeLanguage(lng)
}

Please let me know if I am doing something wrong

1

There are 1 best solutions below

7
PK2995 On
this.localize.changeLanguage(lng) here what you doing that might be affecting changing the route

if you using ngx-translate you can change the language just by using the below method

if you want to change the route as well checkout out this solution Angular2 - route with language

constructor(private translate: TranslateService) {
    translate.setDefaultLang('en'); // default language (in app.component)
  }
  
  useLanguage(language: string) {
    this.translate.use(language);
  }