Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取设置angular 6 Home route中的可选语言参数_Angular_Angular Routing_Angular Router Params - Fatal编程技术网

获取设置angular 6 Home route中的可选语言参数

获取设置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

我试图在url中传递一个语言代码,比如
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`
     });