在app的共享模块中加载额外的路由

问题描述 投票:0回答:1

我有3个模块:

  • app模块(app:consumer)
  • app routing module(定义app的路由:consumer)
  • 共享库模块:不同消费者使用的模块(app模块)

应用程序路由模块定义应用程序的路由。

const appRoutes: Routes = [
  // lazy feature module (routed module)
  { path: 'doc', loadChildren: '../doc/modules/doc.module#DocModule' },
  { path: 'test', loadChildren: '../test/modules/test.module#TestModule' },
  {
     path: '',
     redirectTo: 'doc',
     pathMatch: 'full'
  }
];

app模块导入此应用程序路由模块。

现在我希望能够在共享库中注入额外的路由(比如找不到页面)。

我试着像这样定义它。

const coreRoutes: Routes = [
{ path: '**', component: PageNotFoundComponent }

];

并使用forChild方法:

RouterModule.forChild(coreRoutes)

但问题是我无法再导航到应用路由路由。一切都找不到页面......

angular angular-routing angular-router
1个回答
1
投票

首先,我们需要导入应用程序路由模块,然后才能导入共享模块(顺序很重要)。

© www.soinside.com 2019 - 2024. All rights reserved.