Angular 子模块中的角度多路径
如果我有一个角度模块,有这些路径Angular 子模块中的角度多路径,angular,routes,Angular,Routes,如果我有一个角度模块,有这些路径 const routes: Routes = [ {path: 'route1', children: [ {path: '', component: route1Component} ]}, {path: 'route2', children: [ {path: '', component: route2Component} ]}, {path: 'route3', children: [ {path: '', co
const routes: Routes = [
{path: 'route1', children: [
{path: '', component: route1Component}
]},
{path: 'route2', children: [
{path: '', component: route2Component}
]},
{path: 'route3', children: [
{path: '', component: route3Component}
]}
];
然后,我如何使用父模块中的路由,在那里我将延迟加载。
通常我会这样做
{path: 'route1', loadChildren: () => import('../child.module').then(m => m.ChildModule)}
但这种正常情况意味着子路由有一个默认路由,这里我有3个
我只想导入该模块,并从该模块获取所有路由您必须提供任何一条路由作为默认路由到延迟加载的路由器。 所以我建议只定义默认路由器并将其重定向到第一条路由 因此,您可以使用以下代码:
const routes: Routes = [
{path:''',redirectTo:'route1',pathMatch:'full'},
{path: 'route1', children: [
{path: '', component: route1Component}
]},
{path: 'route2', children: [
{path: '', component: route2Component}
]},
{path: 'route3', children: [
{path: '', component: route3Component}
]}
];
这将解决您不定义任何默认路由器的问题。您必须在延迟加载中为路由器提供任何一条默认路由。 所以我建议只定义默认路由器并将其重定向到第一条路由 因此,您可以使用以下代码:
const routes: Routes = [
{path:''',redirectTo:'route1',pathMatch:'full'},
{path: 'route1', children: [
{path: '', component: route1Component}
]},
{path: 'route2', children: [
{path: '', component: route2Component}
]},
{path: 'route3', children: [
{path: '', component: route3Component}
]}
];
这将解决您没有定义任何默认路由器的问题。谢谢,但这并不能完全解决我的问题。然后如何从父级路由到“route2”和“route3”?然后必须在route1中放置一些链接以重定向到route2和route3。如果您不想这样说,那么就没有办法将它们作为一个模块使用并保持直接链接,那么最好是创建三个子模块。您与基本概念相冲突。谢谢。是的,这是我第一次遇到这个问题。我只是简单地将组件添加到父模块中,尽管它不是idealthanks,但它并不能完全解决我的问题。然后如何从父级路由到“route2”和“route3”?然后必须在route1中放置一些链接以重定向到route2和route3。如果您不想这样说,那么就没有办法将它们作为一个模块使用并保持直接链接,那么最好是创建三个子模块。您与基本概念相冲突。谢谢。是的,这是我第一次遇到这个问题。我只是简单地将组件添加到父模块中,尽管这并不理想