当查询字符串值为1时,Angular2 routeLink不起作用

时间:2016-03-16 21:02:26

标签: angular angular2-routing routelink

我有这个路由器链接:

<a [routerLink]="['RepairReturnListing', {country: someVal}]">Test</a>

在我的组件中,我将someVal定义为:

export class RepairReturnCountByCountry {
   ...
   someVal: number = 1;
   ...
}

当值为1时,我会收到以下网址:

http://localhost:54675/repairReturnListing?country

注意,没有等号和没有价值 我在div中显示值,它按预期工作。

<div>{{someVal}}</div>

如果我将其更改为除1之外的任何内容(甚至-1),我会得到一个有效的网址:

http://localhost:54675/repairReturnListing?country=0
http://localhost:54675/repairReturnListing?country=2
http://localhost:54675/repairReturnListing?country=777
http://localhost:54675/repairReturnListing?country=-1

如果我从组件中删除someVal:

http://localhost:54675/repairReturnListing?country=null

我将someVal更改为字符串,但结果相同:

 someVal: string = '1';

这是我的routeConfig:

 @RouteConfig([
        { path: '/repairReturnListing', name: 'RepairReturnListing', component: ListingComponent, useAsDefault: false }
])

0 个答案:

没有答案