Angular 如何在一个延迟加载模块中管理多个路由
这是站点信息路由模块Angular 如何在一个延迟加载模块中管理多个路由,angular,Angular,这是站点信息路由模块 const routes: Routes = [ { path: '', children: [ { path: '', component: WhyUsComponent }, { path: '', component: WhoWeAreComponent }, { path: '', component: WhatWeDoComponent }
const routes: Routes = [
{
path: '', children: [
{
path: '',
component: WhyUsComponent
},
{
path: '',
component: WhoWeAreComponent
},
{
path: '',
component: WhatWeDoComponent
}
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class SiteInfoRoutingModule { }
下面是应用程序路由模块。问题是所有路由的routerLink都转到第一个组件,这就是为什么我们在站点信息模块中。 如果我在应用程序路由模块中保留路径为空,并在站点信息路由模块中的相应路径中添加为什么我们是谁以及我们的职业生涯,那么它可以工作,但这是管理它的最佳方式吗
{
path: 'why-us',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'who-we-are',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'what-we-do',
loadChildren: './site-info/site-info.module#SiteInfoModule',
}
实际上,您没有在延迟加载的模块中链接路由
const routes: Routes = [
{
path: '',
children: [
{
path: '',
redirectTo: 'why-us',
pathMatch: 'full'
{
path: 'why-us',
component: WhyUsComponent
},
{
path: ''who-we-are',
component: WhoWeAreComponent
},
{
path: 'what-we-do',
component: WhatWeDoComponent
}
]
}
];
以及主路由模块:
{
path: 'site-info',
loadChildren: './site-info/site-info.module#SiteInfoModule'
},
实际上,您没有在延迟加载的模块中链接路由
const routes: Routes = [
{
path: '',
children: [
{
path: '',
redirectTo: 'why-us',
pathMatch: 'full'
{
path: 'why-us',
component: WhyUsComponent
},
{
path: ''who-we-are',
component: WhoWeAreComponent
},
{
path: 'what-we-do',
component: WhatWeDoComponent
}
]
}
];
以及主路由模块:
{
path: 'site-info',
loadChildren: './site-info/site-info.module#SiteInfoModule'
},
这表明,每当您获得路径
为什么我们
加载站点信息模块
{
path: '',
redirectTo: 'why-us',<=== deafult loading path
pathMatch: 'full',
},
{
path: 'why-us',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'who-we-are',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'what-we-do',
loadChildren: './site-info/site-info.module#SiteInfoModule',
}
{
路径:“”,
重定向到:'why us',这告诉您,无论何时获得路径why us
loadSiteInfoModule
{
path: '',
redirectTo: 'why-us',<=== deafult loading path
pathMatch: 'full',
},
{
path: 'why-us',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'who-we-are',
loadChildren: './site-info/site-info.module#SiteInfoModule',
},
{
path: 'what-we-do',
loadChildren: './site-info/site-info.module#SiteInfoModule',
}
{
路径:“”,
重定向至:“为什么是我们”,为什么pathMatch仅在第一个选项中为“完整”,而在其他选项中为“完整”。如果您想了解有关pathMatch的更多信息,请查看您试图访问的确切路径。路径应如下所示:localhost:4200/站点信息/为什么usi期望localhost:4200/为什么是我们..我们可以设置为localhost:4200/为什么是我们不应该ma吗请为所有这三个组件创建不同的模块。path:“”,loadChildren:“./site info/site info.module#SiteInfoModule”
工作时会考虑为什么pathMatch仅在第一个模块中“full”而不在另一个模块中。如果您想了解有关pathMatch的更多信息,请查看您试图访问的确切路线?路线应该看起来像li比如:localhost:4200/站点信息/为什么usi期望localhost:4200/为什么我们..我们能把它设为localhost:4200/为什么我们不可以吗?我应该为这三个组件设置不同的模块。path:'',loadChildren:'./site-info/site-info.module#SiteInfoModule