无法使路由使用2级延迟加载模块(嵌套)

use*_*284 6 angular4 angular

我一直在尝试使用主模块和3个产品模块创建一个基于cli的示例angular4应用程序(产品本身是一个路径参数,可以懒洋洋地加载每个产品屏幕).

这是我的样本 - https://github.com/shankarvn/angular4lazyloading

重现步骤

在浏览器localhost:4003 =>应该加载3张显示product1,product2和product3的卡片.此时,单击product1,您将看到路径更改和product1加载的ui.现在单击Dashboard,您将在控制台中看到错误

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'product1/dashboard'
Error: Cannot match any routes. URL Segment: 'product1/dashboard'
    at ApplyRedirects.noMatchError (router.es5.js:1404) [angular]
    at CatchSubscriber.selector (router.es5.js:1379) [angular]
    at CatchSubscriber.error (catch.js:104) [angular]
Run Code Online (Sandbox Code Playgroud)

不确定我做错了什么 - 只是在延迟加载product1模块时加载仪表板路径.加载product1模块时,不应该注册路由.任何帮助表示赞赏.

谢谢.

yur*_*zui 11

你不应该使用 pathMatch: 'full'

export const Product1Routes: Routes = [
  {
    path: '',
    component: Product1Component,
    children:[
      {
        path: 'dashboard',
        loadChildren: 'app/product1/dashboard/dashboard.module#DashboardModule'
        // or './dashboard/...
      },
      {
        path: '',
        component: Product1ViewComponent
      }
    ]
  }
];
Run Code Online (Sandbox Code Playgroud)

我也改变了loadChildren路径.(补充app/product1)

在此输入图像描述

为什么要HttpModule为每个延迟加载的模块导入?

这在延迟加载的模块中也是多余的

providers: [{ provide: LocationStrategy, useClass: HashLocationStrategy }],
Run Code Online (Sandbox Code Playgroud)

PS我会为每个模块创建路由模块

app-routing.module.ts
product1-routing.module.ts
dashboard-routing.module.ts
Run Code Online (Sandbox Code Playgroud)

等等