如何解决子模块中的成角度的多条路线
如果我有Angular模块,这些路线
const routes: Routes = [
{path: 'route1',children: [
{path: '',component: route1Component}
]},{path: 'route2',component: route2Component}
]},{path: 'route3',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',component: route2Component}
]},{path: 'route3',component: route3Component}
]}
];
这将解决您未定义任何默认路由器的问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。