angularjs - ui-router change url after $state.go -


i have route:

$stateprovider.state('keeper.telepay.category', {     url: '/category-{id}/country-{cid}/region-{rid}' } 

in cases when use $state.go route, want change rid 'all' if it's value '0', url'll

/category-1/country-195/region-all

i've tried in $rootscope.$on('$statechangestart'), no luck. suggestions || directions appreciated.

update

here i've tried on $statechange:

$rootscope.$on('$statechangestart', function(event, tostate, toparams, fromstate, fromparams){     if(tostate.name == 'keeper.telepay.category' && tostate.params.rid == 0) {         tostate.params.rid = 'all';     } } 

accidently i've stumbled link http://angular-ui.github.io/ui-router/feature-1.0/interfaces/params.paramdeclaration.html#squash

so pure solution is:

$stateprovider.state('keeper.telepay.category', {     url: '/category-{id}/country-{cid}/region-{rid}',     params: {         cid: '195',         rid: {             value: '0',             squash: "all" <-- trick         }     } }); 

and here description:

configures how default parameter value represented in url when current parameter value same default value.

there 3 squash settings:

false: parameter's default value not squashed. encoded , included in url

true: parameter's default value omitted url. if parameter preceeded , followed slashes in state's url declaration, 1 of slashes omitted. can allow cleaner looking urls.

"arbitrary string": parameter's default value replaced arbitrary placeholder of choice.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -