Angular2路由器-辅助路由 [英] Angular2 router - Auxiliary route

查看:68
本文介绍了Angular2路由器-辅助路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实有一个延迟加载的模块,当我转到/lazy时,默认情况下会加载LazyLoadedComponent.到目前为止,还可以.

I do have a lazy loaded module which loads by default LazyLoadedComponent when I go to /lazy. So far, it's OK.

此组件包含2个路由器出口:

This component contains 2 router-outlet :

<router-outlet></router-outlet>
<router-outlet name="aux"></router-outlet>

该模块具有以下路由:

const routes = [
  {
    path: '',
    component: LazyLoadedComponent,
    children: [
      {
        path: '',
        component: NonAuxComponent
      },
      {
        path: '',
        component: AuxComponent,
        outlet: 'aux'
      }
    ]
  }
];

当我进入/lazy时,确实按预期加载了3个组件. 但是,如果我想更改显示像这样的AuxComponent的路径:

When I go to /lazy I do have the 3 components loaded as expected. But, if I want to change the path to display the AuxComponent like that :

{
   path: 'auxpath',
   component: AuxComponent,
   outlet: 'aux'
}

然后我尝试转到/lazy(aux:auxpath),它不起作用.

And I try to go to /lazy(aux:auxpath) it's not working.

我也尝试使用routerLink来访问该网址:

I also tried to hit that url using the routerLink like that :

<a [routerLink]="[{ outlets: { aux: 'auxpath' } }]">Load an auxiliary route</a>

但是它也不起作用.

这是路由器的错误吗?只是我在这里错过了什么吗?

Is this a bug with the router ? Is it just me missing out something here?

您可以查看 Plunkr 进行自己的测试.

You can check out the Plunkr to make your own tests.

推荐答案

尝试了很多事情之后,我得出的结论是它可能是@angular/router中的错误.

After trying a lot of things, I ended up with the conclusion that it was probably a bug in @angular/router.

我创建了 Github问题,结果发现自8月以来已经存在一个.

这篇关于Angular2路由器-辅助路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆