我在Angular2中遇到路由问题。
我的问题:
请参阅下面的我的路由代码。第一个版本运行正常。当我创建到的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",
这是一个已知的错误。
我报告说一个月前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] 删除。
我来说两句