更改状态而不更改角度ui路由器中的浏览器历史记录 [英] Changing state without changing browser history in angular ui-router

查看:76
本文介绍了更改状态而不更改角度ui路由器中的浏览器历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有这样的逻辑:

Assume that we have a logic like this:

  • 从状态A更改为状态B.
  • 无论何时到达状态B,应用程序始终通过调用$state.go(stateC)
  • 将我们重定向到状态C
  • 现在我们处于状态C
  • 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

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

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)

推荐答案

使用值为"replace" ...

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

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

位置-{boolean = true | string =}-如果true将更新位置栏中的网址,如果false不会更新.如果为字符串,则必须为"replace",这将更新url并替换上一个历史记录.

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.

这篇关于更改状态而不更改角度ui路由器中的浏览器历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆