获取设置angular 6 Home route中的可选语言参数
我试图在url中传递一个语言代码,比如获取设置angular 6 Home route中的可选语言参数,angular,angular-routing,angular-router-params,Angular,Angular Routing,Angular Router Params,我试图在url中传递一个语言代码,比如localhost4200/en-us/,然后在子组件中获取语言代码,但它不起作用,当我尝试像这样导航localhost4200/en-us/时,我的应用程序开始从localhost4200/en-us/assets/img.png请求资源。这是一个简单的单页网站与角度 应用程序路由模块 主页路由模块 获取Index1组件中的路由器参数 如果我导航到localhost4200/en-us/app无法按预期工作,并且它开始从localhost4200/en-u
localhost4200/en-us/
,然后在子组件中获取语言代码,但它不起作用,当我尝试像这样导航localhost4200/en-us/
时,我的应用程序开始从localhost4200/en-us/assets/img.png
请求资源。这是一个简单的单页网站与角度
应用程序路由模块
主页路由模块
获取Index1组件中的路由器参数
如果我导航到localhost4200/en-us/
app无法按预期工作,并且它开始从localhost4200/en-us/assets请求资源
我还在学习角度布线,我做错了什么?有没有办法设置这个动态语言参数,我希望它是可选的localhost4200/
和localhost4200/en-us
{ path: '', component: LayoutComponent, loadChildren: './pages/pages.module#PagesModule' },
{ path: ':locale', redirectTo: '', pathMatch: 'full' }, // for language param
{ path: 'login', component: LoginComponent },
{ path: '', component: Index1Component },
//{ path: ':locale', redirectTo: '', pathMatch: 'full' }, // tried here also
this._route.params.subscribe(
(param: any) => {
let language = param['locale'];
console.log(language); //it always returns `undefined`
});