2016-08-02 27 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