无法匹配路由索引

时间:2016-08-22 14:40:58

标签: angularjs angular

使用最新版本的angular 2路由器(3.0.0-rc.1)和角度2(RC5)。我的路由器有以下路由:

{ path: 'transport', redirectTo: 'transport/entity-list', pathMatch: 'full'},
{ path: 'transport/entity-list', component: EntityListComponent },
{ path: 'transport/cover-list', component: CoverListComponent },
{ path: 'transport/invoice-list', component: InvoiceListComponent },
{ path: 'transport/damage-list', component: DamageListComponent }

我的服务器(ExpressJS)有pug库并呈现我的索引如下:

res.render('index');

我的index.pug

中也有基本标签
head
    base(href="/")

MyComponent我也导入了ROUTER_DIRECTIVES

当我加载索引时,所有内容都会呈现,但我收到以下错误:

Error: Uncaught (in promise): Error: Cannot match any routes: 'index'

根据我的理解,有角度的路由器正试图路由索引,但在路径中没有看到它。所以我尝试添加index作为路径,但得到:

Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'MyComponent'

我有两个问题:

  1. 我做错了什么,如何摆脱这个错误?
  2. 如何从一开始就获得索引加载transport/entity-list

2 个答案:

答案 0 :(得分:1)

您必须将pathMatch: 'full'添加到您而不是useAsDefault

{ path: 'transport', redirectTo: 'transport/entity-list', pathMatch: 'full'},

答案 1 :(得分:1)

您在路由中缺少索引路径,因此您所做的是正确的。

对于您的其他问题:

Error: Uncaught (in promise): Error: Cannot find primary outlet to load 'MyComponent'

您是否在模板上定义了这个?

<router-outlet></router-outlet>
相关问题