2016-08-02 51 views
0

有一个angular2路由器的问题,似乎当我点击一个链接[routerLink]="['/url']它的控制台给我一个错误ORIGINAL EXCEPTION: TypeError: Cannot read property 'startsWith' of undefined。但是,如果我删除routerLink,只是把一个正常的href它工作正常。angular2 startsWidth未定义的错误

我根本没有改变任何东西,这个错误刚刚出现无处不在。可以在我的代码中找到任何东西,所以不确定它是否存在依赖性问题。有没有其他人有这个问题?

<a [routerLink]="['/reserve']" class="float-shadow"> 
         Reserve &amp; Collect 
        </a> 

import { Component } from '@angular/core'; 
 
import { provideRouter, RouterConfig, CanActivate } from '@angular/router'; 
 
import { LoginComponent } from '../login/component/login'; 
 
import { DashboardComponent } from '../dashboard/component/dashboard'; 
 
import { dragulaCompoment } from '../draggable/components/drag'; 
 
import { AuthGuard } from './authguard' 
 

 
export const routes: RouterConfig = [ 
 
    { path: '', component: LoginComponent }, 
 
    { path: 'home', component: DashboardComponent }, 
 
    { path: 'reserve', component: dragulaCompoment, canActivate: [AuthGuard] }, 
 
    { path: 'order', component: dragulaCompoment, canActivate: [AuthGuard] }, 
 
    { path: 'save', component: dragulaCompoment, canActivate: [AuthGuard] }, 
 
    { path: 'assisted', component: dragulaCompoment, canActivate: [AuthGuard] } 
 
]; 
 

 
export const APP_ROUTER_PROVIDERS = [ 
 
    provideRouter(routes) 
 
];

Packacge.json角依赖性

"@angular/common": "2.0.0-rc.4", 
"@angular/compiler": "2.0.0-rc.4", 
"@angular/core": "2.0.0-rc.4", 
"@angular/forms": "0.2.0", 
"@angular/http": "2.0.0-rc.4", 
"@angular/platform-browser": "2.0.0-rc.4", 
"@angular/platform-browser-dynamic": "2.0.0-rc.4", 
"@angular/router": "3.0.0-beta.1", 
"@angular/router-deprecated": "2.0.0-rc.2", 
"@angular/upgrade": "2.0.0-rc.4", 
"angular2-in-memory-web-api": "0.0.14", 

enter image description here

+0

你有没有试图消除'/' – AngJobs

+0

请发表您的路线和其组件包含routerLink。 –

+0

这是一个已知问题,https://github.com/angular/angular/issues/9499 – AngJobs

回答

0
{ path: '', component: LoginComponent }, 

{ path: '', component: LoginComponent, pathMatch: 'full' }, 

否则所有的路径将被视为孩子航线''

+0

什么,它是如何工作,然后即使没有pathMatch。试试这个 – nCore

+0

你的问题并不表明它正在工作;-)你没有提供太多的信息,但对我来说,它看起来像你试图完成它需要它。 –

+0

哦,我在给Angjobs的回复中提到过,我已经将pathMatch添加到了路径中:''但仍然无法使用。我是否必须在每条路线中添加它? – nCore