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

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

问题描述

假设我们有这样的逻辑:

Assume that we have a logic like this:

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

推荐答案

使用 location 选项和值 "replace"...

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

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

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

location - {boolean=true|string=} - 如果 true 将更新地址栏中的 url,如果 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-router 中的浏览器历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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