我使用$stateProvider
定义了以下状态:
$stateProvider.state("byTeams", {url : "/team/{id}/{year}", ...})
$stateProvider.state("byPlayer", {url : "/player/{id}/{year}", ...})
更改一年时,如果网址与默认值匹配(例如2014年),我希望该网址省略网址的{year}
部分。换句话说,何时:
$state.go("byTeams", {year: 2014}) --> www.example.com/app/#/team/343
$state.go("byTeams", {year: 2013}) --> www.example.com/app/#/team/343/2013
当我切换到byPlayer
视图时(假设年份是2014年 - 默认):
$state.go("byPlayer", {id: 555}) --> www.example.com/app/#/player/555/
否则,网址为:www.example.com/app/#/player/555/2013
答案 0 :(得分:14)
在docs
中阅读params
的{{3}}和squash
$stateProvider.state("byPlayer", {
url : "/player/{id}/{year}",
params: {
year: {
value: function() { return getCurrentYear(); },
squash: true
}
}
})