Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing state without changing browser history in angular ui-router

Assume that we have a logic like this:

  • From state A, change to state B.
  • Whenever we arrive to state B, the app always redirect us to state C by calling $state.go(stateC)
  • Now we are in state C

My question is how to go back to state A from state C (given the fact that state A can be any state we don't know at run-time, meaning user can access state B from any other states)

like image 506
Thịnh Phạm Avatar asked Sep 13 '16 02:09

Thịnh Phạm


1 Answers

Use the location option with value "replace"...

$state.go(stateC, null, {
    location: 'replace'
})

See https://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$state#methods_go

location - {boolean=true|string=} - If true will update the url in the location bar, if false will not. If string, must be "replace", which will update url and also replace last history record.

like image 170
Phil Avatar answered Nov 07 '22 18:11

Phil