angular2延迟加载模块路由
我在我的主路线模块上看到了这个:angular2延迟加载模块路由,angular,routes,Angular,Routes,我在我的主路线模块上看到了这个: { path: 'alpha/aaa', loadChildren: 'app/connection/connection.module#ConnectionModule' }, { path: 'num/123', loadChildren: 'app/connection/connection.module#ConnectionModule' }, { path: 'rand/a2b1'
{
path: 'alpha/aaa',
loadChildren: 'app/connection/connection.module#ConnectionModule'
},
{
path: 'num/123',
loadChildren: 'app/connection/connection.module#ConnectionModule'
},
{
path: 'rand/a2b1',
loadChildren: 'app/connection/connection.module#ConnectionModule'
},
路由不同,但它们位于一个模块中,因为它们具有相同的模板和功能
我的问题是,如果子模块的路径正是我需要的路径,我将如何映射上面定义的路径?因此,我尝试了以下方法,但没有成功:
const routes: Routes = [
{ path: 'alpha/aaa', pathMatch:'full', component: Component1 },
{ path: 'num/123', pathMatch:'full', component: Component2 },
{ path: 'rand/a2b1', pathMatch:'full', component: Component3 }
];
不幸的是,这是不可能做到的,但是如果您改变您的路线并为整个模块提供一个公共路线,您可以实现类似的效果。即:
{
path: 'connection',
loadChildren: 'app/connection/connection.module#ConnectionModule'
}
然后就像你现在做的那样
const routes: Routes = [
{ path: 'alpha/aaa', component: Component1 },
{ path: 'num/123', component: Component2 },
{ path: 'rand/a2b1', component: Component3 }
];
然后您可以像这样访问它们
/connection/alpha/aaa
/connection/num/123
/connection/rand/a2b1
这样行吗?{路径:'',组件:WeAreSharingComponent}现在!编辑:)!它们使用不同的组件。这个如何:{path:'/alpha/aaa',组件:Component1}斜杠在前面表示非相对路径?尝试过,但不起作用。我可以将每个模块分开,以拥有自己的模块,并为这三个模块创建一个公共模块。我只是在想一定有办法让它发挥作用。我不敢相信有人没有同样的问题。