如何通过路由器链接传递参数并进入延迟加载模块?

时间:2019-05-02 05:51:48

标签: angular6 lazy-loading router angular-routerlink

我正在尝试设置参数并在延迟加载模块中获取该参数,但我不知道该怎么做。

我做了这样的事情 在 app-routing.module.ts

const routes: Routes = [
  { path: '', loadChildren: './layout/layout.module#LayoutModule'},
  { path: 'login', loadChildren: './login/login.module#LoginModule' }
];

@NgModule({
  imports: [
    CommonModule, RouterModule.forRoot(routes)
  ],
  exports: [RouterModule],
  declarations: []
})

layout-routing.module.ts

const routes: Routes = [
  {
    path: '',
    component: LayoutComponent,
    children: [
      { path: '', redirectTo: 'dashboard' },
      { path: 'dashboard', loadChildren: './dashboard/dashboard.module#DashboardModule'}
    ]
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})

dashboard-routing.module.ts

const routes: Routes = [
  {
    path: ':id',
    component: DashboardComponent
  }
];

@NgModule({
  imports: [RouterModule.forChild(routes)],
  exports: [RouterModule]
})

最后在侧面菜单中,我传递了参数链接:

**

<a  routerLink="['/dashboard', '15']" [routerLinkActive]="['router-link-active']"> <i class="material-icons"></i><span>Fan 1</span></a>

**

当我尝试运行应用程序时,它给了我一个错误:

core.js:1673错误错误:未被捕获(承诺):错误:无法匹配任何路由。 URL段:“ dashboard / dashboard” 错误:无法匹配任何路线。网址段:“仪表板/仪表板”

0 个答案:

没有答案