我正在尝试使用 Angular2 路由器重现我的问题,但我无法在 Plunker 中创建我的项目的工作副本。
这是我的尝试:https://plnkr.co/edit/1lpoYP4qlBZLuqZHW7Ft
我在 index.html
文件中使用了以下代码行,使路由路径与 Plunker 的运行环境和我的 ''
默认路径一起工作。
<script>document.write('<base href="' + document.location + '" />');</script>
为什么我仍然收到此错误?
最佳答案
您的 plnkr 中有一个小错别字:
loadChildren: 'app/拳头-section.module#FirstSectionModule'
可能是第一个 ;)
还有一个问题:即使是 child 也需要一个空的
''
-path。所以不用写
children :[
{ 路径:'第一节',loadChildren:'app/first-section.module#FirstSectionModule' }
]
您应该添加一个空路径并重定向到 first-section
-path,如下所示:
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) 不再需要为子路由使用空路径。
我用最新的 angular 2.4.1 版本更新了 plunker:PLUNKER .该示例现在正在运行,没有空路径。
关于angular - 错误 : Cannot match any routes. URL 段: '',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40132186/