I have the following states defined with $stateProvider
:
$stateProvider.state("byTeams", {url : "/team/{id}/{year}", ...})
$stateProvider.state("byPlayer", {url : "/player/{id}/{year}", ...})
When changing a year, I would like the URL to omit the {year}
part of the URL if it matches the default (say 2014). In other words, when:
$state.go("byTeams", {year: 2014}) --> www.example.com/app/#/team/343
$state.go("byTeams", {year: 2013}) --> www.example.com/app/#/team/343/2013
And when I switch to a byPlayer
view (assuming the year is 2014 - default):
$state.go("byPlayer", {id: 555}) --> www.example.com/app/#/player/555/
Otherwise, the URL would be: www.example.com/app/#/player/555/2013
Read the docs for params
and squash
in $stateProvider.state()
$stateProvider.state("byPlayer", {
url : "/player/{id}/{year}",
params: {
year: {
value: function() { return getCurrentYear(); },
squash: true
}
}
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With