有了angular2路由器的问题,当我点击[routerLink]="['/url']
的链接时,它似乎给我一个错误ORIGINAL EXCEPTION: TypeError: Cannot read property 'startsWith' of undefined
。但是,如果我删除了routerLink
并只是放了一个普通的href
,那就可以了。
我根本没有改变任何事情,这个错误就是冒出来的。可以在我的代码中找到任何内容,因此不确定它是否是依赖问题。还有其他人有这个问题吗?
<a [routerLink]="['/reserve']" class="float-shadow">
Reserve & 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)
];
&#13;
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",
答案 0 :(得分:0)
{ path: '', component: LoginComponent },
应该是
{ path: '', component: LoginComponent, pathMatch: 'full' },
否则所有路径都将被视为''