Show component in nested router

蹲街弑〆低调 提交于 2019-12-11 10:54:49

问题



I want to route to "config" router, which is nested 2 outlets deep but I'm unable to figure out the correct way to do so.
<router>
  <router name="main">
    <router name="config">
    </router>
  </router>
</router>

In my routing.ts, I created 2 ways to reach the component:

export const routes: Routes = [
  {
    // Entrypoint.
    path: 'Foo', component: FooComponent, canActivate: [IsServerOnlineGuard], children: [
        path: 'Bar', component: BarComponent, outlet: 'main', children: [
          { path: 'Smtp', component: smtpComponent, outlet: 'config' } // registered as a child
        ],
        path: 'Smtp', component: smtpComponent, outlet: 'config' }, // registered under the "main" component
      },
    ]
  },
  { path: '', pathMatch: 'full', redirectTo: 'CSI' },
  { path: '**', redirectTo: 'CSI' },
];

I tried navigating there in 2 ways.

public RouteToConfigOutlet(componentName: string) {
  this._router.navigate([`/(main:BarComponent)/`, {
    outlets: {
      config: ['Smtp']
    }
  }]);
}

public RouteToConfigOutlet(componentName: string) {
  this._router.navigate([``, {
    outlets: {
      main: ['BarComponent'],
      config: ['Smtp']
    }
  }]);
}

Alas I'm unable to get my component to show up and am trying to find the correct way to get there.


回答1:


I found the answer on this website. The correct way of routing is:

router.navigate(
[{
   outlets: {
      'main': ['BarComponent',
         { outlets: { 'config': ['smtpComponent'] } } ]
   }
}]);


来源:https://stackoverflow.com/questions/58381534/show-component-in-nested-router

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!