ngx-i18n-router
ngx-i18n-router copied to clipboard
access route based on language set in url
I have followed your guide which is great. However, I have something not working. Basically, my router looks like this:
const routes: Routes = [
{
path: '', children: [
{
path: 'dummy', component: DummyComponent
}
],
data: {
i18n: {
isRoot: true
}
}
},
{
path: 'change-language/:languageCode',
component: ChangeLanguageComponent
},
{
path: '**',
redirectTo: '',
pathMatch: 'full'
}
];
@NgModule({
imports: [RouterModule.forRoot(routes),
I18NRouterModule.forRoot(routes, [
{
provide: I18NRouterLoader,
useFactory: (i18nRouterFactory),
deps: [Http, RAW_ROUTES]
}
])
],
exports: [RouterModule, I18NRouterModule ]
})
export class AppRoutingModule { }
and in my routes.json:
{
"en": {
"ROOT.DUMMY":"dummyen"
},
"fr": {
"ROOT.DUMMY":"dummyfr"
}
}
app.component.ts
export class AppComponent implements OnInit {
constructor(private readonly i18nRouter: I18NRouterService) {
i18nRouter.init()
}
ngOnInit() {
this.i18nRouter.changeLanguage('en');
}
}
If I try to access en/dummyen it works fine. However if I try to access, directly by modifying the url fr/dummyfr it doesn't work. Which is normal since I would need to do a this.i18nRouter.changeLanguage('fr');
I am just not sure how to do this. Is this something I should be able to do ?
+1
Any plan to upgrade to angular 6?