Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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
Angular6路由器导航到共享同一组件的多个子路由_Angular_Typescript_Angular6_Angular Routing - Fatal编程技术网

Angular6路由器导航到共享同一组件的多个子路由

Angular6路由器导航到共享同一组件的多个子路由,angular,typescript,angular6,angular-routing,Angular,Typescript,Angular6,Angular Routing,我有多个子组件,它们共享同一个工作正常的组件,但是,我无法在页面之间进行路由,因为组件似乎已经加载。尝试路由到这些子路由时,是否可以重新加载组件 const ServicesRouting: ModuleWithProviders = RouterModule.forChild([ { path: '', component: StructureComponent, canActivate: [AuthGuard], chi

我有多个子组件,它们共享同一个工作正常的组件,但是,我无法在页面之间进行路由,因为组件似乎已经加载。尝试路由到这些子路由时,是否可以重新加载组件

const ServicesRouting: ModuleWithProviders = RouterModule.forChild([
    {
        path: '',
        component: StructureComponent,
        canActivate: [AuthGuard],
        children: [
            {
                path: 'services',
                canActivate: [AuthGuard],
                component: servicesComponent,
                children: [
                    {
                        path: 'one',
                        canActivate: [AuthGuard],
                        component: servicesComponent,
                    },
                    {
                        path: 'two',
                        canActivate: [AuthGuard],
                        component: servicesComponent,
                    },
                    {
                        path: 'three',
                        canActivate: [AuthGuard],
                        component: servicesComponent,
                    },
                    {
                        path: 'four',
                        canActivate: [AuthGuard],
                        component: servicesComponent,
                    }
                ]
            }
        ]
    }
]);

您首先必须为每个路由创建相同的页面,并使用如下参数:
path:'home/:id'

但这并不能解决你的问题。 你必须在那里使用RXJS。例如:


此.route.paramMap
.烟斗(
map((paramMap)=>Number.parseInt(paramMap.get('id')| |'1',10)),
switchMap((id)=>this.myService.getData(id))
).subscribe((数据)=>this.data=data);


this.route.paramMap是一个可观察的,您可以订阅。

首先必须为每个路由创建一个相同的页面,并使用如下参数:
path:'home/:id'

但这并不能解决你的问题。 你必须在那里使用RXJS。例如:


此.route.paramMap
.烟斗(
map((paramMap)=>Number.parseInt(paramMap.get('id')| |'1',10)),
switchMap((id)=>this.myService.getData(id))
).subscribe((数据)=>this.data=data);

this.route.paramMap是一个可观察的,您可以订阅。

您可以使用。
例如,尝试以下方法:

{
        path: '',
        component: StructureComponent,
        canActivate: [AuthGuard],
        runGuardsAndResolvers: 'always'
        children: [...]
}
您可以使用。
例如,尝试以下方法:

{
        path: '',
        component: StructureComponent,
        canActivate: [AuthGuard],
        runGuardsAndResolvers: 'always'
        children: [...]
}

看起来AuthGaurd正在阻止它,请删除Gaurd并检查我不太明白,如果每个路由共享同一个组件,为什么要为它们创建不同的页面。你可以使用一个参数,比如so
path:'home/:id'
@GreatHawkeye,你的观点很正确(感觉像个白痴)。我将进行相应的更改并与您联系。@GreatHawkeye我已将路由更新为include/:service,但是,尝试路由时组件的内容保持不变。看起来AuthGaurd正在阻止它,删除Gaurd和Check如果它们共享同一个组件,我不知道为什么要为每个路由创建不同的页面。你可以使用一个参数,比如so
path:'home/:id'
@GreatHawkeye,你的观点很正确(感觉像个白痴)。我将做出相应的更改并与您联系。@GreatHawkeye我已将路由更新为include/:service,但是,尝试路由时组件的内容保持不变。