Angular2 - TypeScript - ng-Translate
Hello people,
I need to change the rest of my url depending on language selected "en/soybean", "fr/soya". In my app.routes I got this path :
{ path: ':lang/soybean', component: SoybeanComponent }
My SoyBean component is translate from the lang param with ng-translate
this.route.params.subscribe(params => {
translate.use(params['lang']);
})
How can I display the url as fr/soya but still use path fr/soybean !?
What I tried
*I create a new path: { path: ':lang/soya', component: SoybeanComponent },
I thought I could redirect the user to the good path :
if(params['lang'] === 'en'){
this.router.navigateByUrl('lang/soybean');
}
if(params['lang'] === 'fr'){
this.router.navigateByUrl('lang/soya');
}
but it will result on a infinite loading.
Then I thought I could hardcode the lang param after redirecting like :
if(params['lang'] === 'en'){
this.router.navigateByUrl('en/soybean');
}
if(params['lang'] === 'fr'){
this.router.navigateByUrl('fr/soya');
}
but in this case I will catch an exception.*
langas both a route parameter and as a constant path route?langdetermine witch language I will use, but it didn't change the path. Iflangis fr then soybean.html and soybean.component will be translate to french. What I want is how can I display the url as fr/soya but still use path fr/soybean ! Sorry for bad explanation I will edit my first post !