具有多个命名插座的延迟加载模块上的Angular2路由

七月

我在Angular2中遇到路由问题。

  1. 我的模块是延迟加载的(但到目前为止,基本的“ loadChildren”方法都没有问题)
  2. 模块本身正在加载(在dev-tools的network-tab中可见)

我的问题:

请参阅下面的我的路由代码。第一个版本运行正常。当我创建到的routerLink时,找到了路由并且未引发任何错误。

但是,为什么我的第一段摘录有效,而第二段却不起作用?我不想为了使此工作而创建伪路径“测试”。在第二个示例中,获取此错误消息。

[...]无法匹配任何路线。网址段:“ mypath” [...]

工作路线:

children: export const routes: Routes = [
    {
        path: '',
        component: ParentSplitViewComponent,
        children: [
            {
                path: '',
                redirectTo: 'test'
            },
            {
                path: 'test',
                component: SplitViewComponent,
                children: [
                    {
                        path: '',
                        redirectTo: 'list'
                    },
                    {
                        path: 'list',
                        component: MyListComponent,
                        outlet: 'left'
                    },
                    {
                        path: ':id',
                        component: MyDetailComponent,
                        outlet: 'right'
                    }
                ]
            }
        ]
    }
];

不起作用的路由:

children: export const routes: Routes = [
    {
        path: '',
        component: ParentSplitViewComponent,
        children: [
            {
                path: '',
                component: SplitViewComponent,
                children: [
                    {
                        path: '',
                        redirectTo: 'list'
                    },
                    {
                        path: 'list',
                        component: MyListComponent,
                        outlet: 'left'
                    },
                    {
                        path: ':id',
                        component: MyDetailComponent,
                        outlet: 'right'
                    }
                ]
            }
        ]
    }
];

请不要依赖文件等的命名。我不得不重命名路径等-从这个角度来看,一切正常。它只是关于路由。

应用路由

{
    path: 'mypath',
    loadChildren: 'app/modules/myModule/my.module#MyModule'
},

懒加载模块的较大摘录,以了解其结构:

import [...]    


@Component({
    selector: 'parent-split-view-layout-container',
    template: `
    <h1>Parent</h1>

    <router-outlet></router-outlet>
  `
});
export class ParentSplitViewComponent {}



@Component({
    selector: 'split-view-layout-container',
    template: `
    <h1>Vertical Split View</h1>

    <div id="left">
        <router-outlet name="left"></router-outlet>
    </div>

    <div id="right">
        <router-outlet name="right"></router-outlet>
    </div>
  `
});
export class SplitViewComponent {}




/* Routing Definition */
export const routes: Routes = [
    {
        path: '',
        component: ParentSplitViewComponent,
        children: [
            {
                path: '',
                redirectTo: 'test'
            },
            {
                path: 'test',
                component: SplitViewComponent,
                children: [
                    {
                        path: '',
                        redirectTo: 'list'
                    },
                    {
                        path: 'list',
                        component: MyListComponent,
                        outlet: 'left'
                    },
                    {
                        path: ':id',
                        component: MyDetailComponent,
                        outlet: 'right'
                    }
                ]
            }
        ]
    }
];

export const MyRouting: ModuleWithProviders = RouterModule.forChild(routes);

Angular2版本:

"@angular/common": "~2.4.5",
"@angular/compiler": "~2.4.5",
"@angular/core": "~2.4.5",
"@angular/forms": "~2.4.5",
"@angular/http": "~2.4.5",
"@angular/material": "^2.0.0-beta.1",
"@angular/platform-browser": "~2.4.5",
"@angular/platform-browser-dynamic": "~2.4.5",
"@angular/router": "~3.4.5",
1992年

这是一个已知的错误。
我报告说一个月前https://github.com/angular/angular/issues/13807
由于与以下内容重复:https : //github.com/angular/angular/issues/10981

我也需要它,但是由于自2016年8月26日以来一直存在问题,并且“ vsavkin在2016年11月16日取消了他们的任务”,我认为我们不会很快看到修复程序。

与辅助路线相比,我最终遇到了非常糟糕的事情,但工作必须跟上。我希望我能为那件事做些贡献,但是我没有...

编辑:(13/06/18)
看起来今天已经合并修复程序

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Angular2路由器错误:找不到主插座以加载“主页”

Angular2路由器:找不到要加载“ HomeComponent”的主要插座

Angular4路由器,延迟加载的模块子路由,命名为路由器出口

使用loadChildren的angular2路由器延迟加载服务不是单例

Angular2路由未由requirejs加载

Angular2路由:是否存在链接参数数组具有多个元素的条件?

具有深度嵌套路由的Angular2路由v3.0.0

Angular2路由:加载两次

Angular2路由器插座组件的样式正固定

在IIS 7.5上使用Angular2路由

延迟加载的功能模块中的Angular 4路由

没有组件的Angular2路由

使用angular2在同一路由器出口中加载多个组件

Angular2路由器:为什么我们在路由上不再有状态

获取Angular2路由器中活动路由上的组件实例?

模块中子应用程序之间的Angular2路由

Angular2路由器-辅助路由

Angular路由器:命名的插座似乎不适用于相对路由,也不适用于延迟加载的模块

Angular 2路由问题:功能模块未在正确的位置加载

Angular2路由配置(带有两个参数的路由)

angular2路由器导航无法正确加载组件

Angular2路由器弃用的依赖项未加载

Angular2路由器:错误:找不到要加载“ InboxComponent”的主要出口

Angular2路由:一次包含多个组件

嵌套Angular2 RC5路由多个文件

具有多个NgModule级别的Angular 6路由

Angular2路由路径样式参数

如何使用Angular2路由

Angular2路由到错误的页面