我在Angular2中遇到了路由问题.
>我的模块是延迟加载的(但到目前为止基本的“loadChildren”方法没问题)
>正在加载模块本身(在dev-tools的网络选项卡中可以看到)
我的问题:
请参阅下面的路由代码.第一个版本正常工作.找到路由,并且在创建routerLink时不会抛出任何错误.
但是,为什么我的第一个摘录工作,第二个不?我不想创建一个伪路径“测试”只是为了让这个工作.第二个例子是获取此错误消息.
[…]Cannot match any routes. URL Segment: ‘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: '',outlet: 'right' } ] } ] } ];
请不要依赖于文件的命名等.我必须重命名路径等 – 从这个角度来看一切正常.它只是关于路由.
App.routing.ts
{ 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: '',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",
解决方法
这是一个已知的错误.
我报道一个月前 https://github.com/angular/angular/issues/13807
它被关闭,因为它是重复的: https://github.com/angular/angular/issues/10981
我报道一个月前 https://github.com/angular/angular/issues/13807
它被关闭,因为它是重复的: https://github.com/angular/angular/issues/10981
我也需要这个,但是自2016年8月26日问题开始以及“vsavkin于2016年11月16日取消了他们的任务”之后,我认为我们很快就会看到修复.
我最终得到了一些非常糟糕的东西,而不是我用辅助路线做的事情,但工作必须跟上.我希望我能够帮助那个,但我不是……
编辑:(13/06/18)
看起来fix今天已经合并了!