angular - Angular Router:将模块加载为延迟加载模块的子模块
问题描述
我有一个复杂的应用程序,我想在其中加载一个模块作为延迟加载模块的子模块。
例如,我想要以下路径:
https://localhost:8080/ui/ examplemodule / new
examplemodule和new都是一个模块,每个都有自己的 routing.config 文件。
我的 app-routing.module.ts 看起来像这样:
const routes: Routes = [
{
path: '',
component: ParentComponent,
canActivate: [LoginRequiredGuard],
children: [
{
path: '',
children: [
{
path: '',
component: HomeComponent,
},
{
path: 'examplemodule',
loadChildren: 'app/my-modules/example/example.module#ExampleModule',
canActivate: [LoginRequiredGuard],
},
{
// examplemodule2
},
{
// examplemodule3
},
{
path: 'new',
loadChildren: 'app/new/new.module#NewModule',
canActivate: [LoginRequiredGuard],
},
],
},
...
NewModule 的 new.routing.ts 文件如下所示:
const routes: Routes = [
{
path: '',
redirectTo: 'new',
pathMatch: 'full'
},
{
path: 'new',
component: NewViewComponent,
},
];
正如我目前所做的那样,我得到一个“找不到资源”。
例如我不想有以下路线:
https://localhost:8080/ui/ examplemodule / new
https://localhost:8080/ui/ examplemodule2 / new
https://localhost:8080/ui/ examplemodule3 / new
我究竟做错了什么?我希望我能解释清楚..
解决方案
我认为您需要NewModule
从内部加载ExampleModule
因此,从 app 模块路由中删除您的new
路径并将此位添加到ExampleModule
's routing
const routes: Routes = [
{
path: '',
component: YourParentComponentForExampleModule,
children: [
{
path: '',
children: [
//All your other paths here
//...
{
path: 'new',
loadChildren: 'app/new/new.module#NewModule',
//canActivate: [LoginRequiredGuard], //You probably don't need it as it's already there on parent module
},
],
},
...
推荐阅读
- reactjs - 在页面 url 上创建事件已更改
- java - Firebase 数据库发生更改后,活动重新启动
- angular - 如何在 Angular 库中使用 Angular 项目中的样式?
- kubernetes - 如何为 Minikube 上的入口控制器指定自定义端口?
- redirect - 通过 www 访问域。重定向到子域
- php - macOS Catalina 更新后 Apache 无法正常工作
- node.js - 将 Mongoose.connect 与 useUnifiedTopology 选项一起使用时,返回的 Promise 不会捕获错误
- asp.net-mvc - 如何在 cshtml 中使用服务器代码检测 IOS 版本?
- python - 如何捕获特定文件的下载次数
- task - 当我运行我的气流时,没有创建任何任务