Error: Cannot match any routes. URL Segment: ''
Error: Cannot match any routes. URL Segment: ''
我正在尝试使用 Angular2 路由器重现我的问题,但我无法在 Plunker 中创建我的项目的工作副本。
这是我的尝试:https://plnkr.co/edit/1lpoYP4qlBZLuqZHW7Ft
我在 index.html
文件中使用了以下代码行,使路由路径与 Plunker 的 运行 环境和我的 ''
默认路径一起工作。
<script>document.write('<base href="' + document.location + '" />');</script>
为什么我仍然收到此错误?
您的 plnkr 中有一个小错别字:
loadChildren: 'app/fist-section.module#FirstSectionModule' }
可能是第一个 ;)
还有一个问题:即使 childrens 也需要一个空的 ''
-path。所以不要写
children: [
{ path: 'first-section', loadChildren: 'app/first-section.module#FirstSectionModule' }
]
您应该添加一个空路径并像这样重定向到 first-section
-路径:
children: [
{ path: '', redirectTo: 'first-section'},
{ path: 'first-section', loadChildren: 'app/fist-section.module#FirstSectionModule' }
]
这是更正后的 plnkr:
https://plnkr.co/edit/9fMwx0?p=preview
更新 Angular 2.4.1:
我注意到使用最新版本的 angular (2.4.1) 不再需要为 children 路由使用空路径。
我用最新的 angular 2.4.1 版本更新了 plunker:PLUNKER。示例 运行 目前没有空路径。
我正在尝试使用 Angular2 路由器重现我的问题,但我无法在 Plunker 中创建我的项目的工作副本。
这是我的尝试:https://plnkr.co/edit/1lpoYP4qlBZLuqZHW7Ft
我在 index.html
文件中使用了以下代码行,使路由路径与 Plunker 的 运行 环境和我的 ''
默认路径一起工作。
<script>document.write('<base href="' + document.location + '" />');</script>
为什么我仍然收到此错误?
您的 plnkr 中有一个小错别字:
loadChildren: 'app/fist-section.module#FirstSectionModule' }
可能是第一个 ;)
还有一个问题:即使 childrens 也需要一个空的
''
-path。所以不要写
children: [
{ path: 'first-section', loadChildren: 'app/first-section.module#FirstSectionModule' }
]
您应该添加一个空路径并像这样重定向到 first-section
-路径:
children: [
{ path: '', redirectTo: 'first-section'},
{ path: 'first-section', loadChildren: 'app/fist-section.module#FirstSectionModule' }
]
这是更正后的 plnkr:
https://plnkr.co/edit/9fMwx0?p=preview
更新 Angular 2.4.1:
我注意到使用最新版本的 angular (2.4.1) 不再需要为 children 路由使用空路径。
我用最新的 angular 2.4.1 版本更新了 plunker:PLUNKER。示例 运行 目前没有空路径。