在角度ui-router中更改状态而不更改浏览器历史记录

Thị*_*hạm 21 browser-history angularjs angular-ui-router

假设我们有这样的逻辑:

  • 从状态A,切换到状态B.
  • 每当我们到达状态B时,应用程序总是通过调用将我们重定向到状态C. $state.go(stateC)
  • 现在我们处于C州

我的问题是如何从状态C回到状态A(假设状态A可以是我们在运行时不知道的任何状态,这意味着用户可以从任何其他状态访问状态B)

Phi*_*hil 36

使用location值为"replace"的选项...

$state.go(stateC, null, {
    location: 'replace'
})
Run Code Online (Sandbox Code Playgroud)

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

location - {boolean = true | string =} - 如果true要更新位置栏中的url,则false不会.如果是string,则必须是"replace",这将更新url并替换最后的历史记录.