Angular 2路由器 – 命名出口

前端之家收集整理的这篇文章主要介绍了Angular 2路由器 – 命名出口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
文档不是很好,但我试图在同一页/路由上有不同的路由器出口.

我的app.component.html中有这个

  1. <router-outlet></router-outlet>
  2. <router-outlet name="dashboard"></router-outlet>

我的app.routes.ts

  1. {
  2. path: '',component: HomeComponent,outlet: 'primary'
  3. },{
  4. path: '',component: DashboardComponent,outlet: 'dashboard'
  5. },{
  6. path: '**',redirectTo: '404'
  7. }

所以在我的首页上(即“example.com”,而非“example.com;仪表板:仪表板”)我想在主路由器插座中显示Home组件,在显示板插座中显示我的Dashboard组件.这适用于ngrs / router,但由于它已被弃用,我正在尝试迁移.没有仪表板:角度/路由器中的仪表板是否可能?

有了这个配置,我正被重定向404.我也试过这个没有运气:

  1. {
  2. path: '',children: [
  3. {
  4. path: '',outlet: 'dashboard'
  5. }
  6. ]
  7. },

有没有人设法让命名的路由器插座工作?

UPDATE
关于从ngrx / router到angular / router的迁移说明,你应该能够:

  1. {
  2. path: 'blog',outlet: 'main'
  3. },{
  4. path: 'blog',component: RegisterComponent,outlet: 'dashboard'
  5. }

但是当我访问example.com/blog时,我在控制台中收到此错误

Error: Cannot match any routes: ‘blog’

https://github.com/ngrx/router/blob/master/docs/overview/migration.md

试试这个配置:
  1. {
  2. path: 'wrap',children: [
  3. {
  4. path: 'dash',outlet: 'dashboard'
  5. }
  6. ]
  7. }

有:

  1. this.router.navigateByUrl('/wrap(dashboard:dash)');

我不知道为什么需要一个url片段(比如我添加的“wrap”)但是它有效……

和其他人:

  1. {
  2. path: 'blog',outlet: 'dashboard'
  3. }

有:

  1. this.router.navigateByUrl('/(main:blog)');
  2. this.router.navigateByUrl('/(dashboard:blog)');

猜你在找的Angularjs相关文章