I'm trying to pass a language code in the url like localhost4200/en-us/
and get the language code inside the child component, but it's not working and when I try to navigate localhost4200/en-us/
like this then my app start to request resources from localhost4200/en-us/assets/img.png
. It is a simple onepage website made with angular.
App routing module
{ path: '', component: LayoutComponent, loadChildren: './pages/pages.module#PagesModule' },
{ path: ':locale', redirectTo: '', pathMatch: 'full' }, // for language param
{ path: 'login', component: LoginComponent },
Home page routing module
{ path: '', component: Index1Component },
//{ path: ':locale', redirectTo: '', pathMatch: 'full' }, // tried here also
Get router param in Index1Component
this._route.params.subscribe(
(param: any) => {
let language = param['locale'];
console.log(language); //it always returns `undefined`
});
if I navigate to localhost4200/en-us/
app doesn't work as expected and it starts to request resources from localhost4200/en-us/assets
I'm still learning Angular routing, what I'm doing wrong here? Is there any way to set this dynamic language parameter and I want it as optional localhost4200/
and localhost4200/en-us
.