Angular ui-router: Can you change state without changing URL?(Angular ui-router:您可以在不更改 URL 的情况下更改状态吗?)
问题描述
ui-router
的 多个嵌套视图 功能非常好 - 您可以轻松地从应用的一个 状态 跳转到另一个.
The multiple nested views functionality of the ui-router
is very nice - you can easily jump from one state of your app to another.
有时您可能想更改 URL,但有时不想.我觉得 state 的概念应该与 routing 分开/可选.
Sometimes you might want to change the URL, but sometimes not. I feel like the concept of state should be separate/optional from routing.
这是一个 plunker,说明了我的意思. 这是 ui-router
文档,有 2 处小改动如下:
Here's a plunker that shows what I mean. This is a fork of one of the plunkers in the ui-router
documentation, with 2 minor changes noted below:
.state('route1', {
url: "/route", // <---- URL IS SHARED WITH ROUTE2
views: {
"viewA": {
template: "route1.viewA"
},
"viewB": {
template: "route1.viewB"
}
}
})
.state('route2', {
url: "/route", // <---- URL IS SHARED WITH ROUTE1
views: {
"viewA": {
template: "route2.viewA"
},
"viewB": {
template: "route2.viewB"
}
}
})
这似乎有效 - URL 保持不变.同样,这里做了多少冗余工作?这是经过批准/测试的用法吗?
This seems to work - the URL stays the same. Again, how much redundant work is done here? Is this an approved/tested usage?
如果您可以从状态中省略 url
那就太好了..
It would be nice if you could omit the url
from a state..
更新问题:这是经过批准/测试的用法吗?
Update question: Is this an approved/tested usage?
推荐答案
你绝对可以拥有一个没有 URL 的状态.事实上,您所在的州都不需要 URL.这是设计的核心部分.话虽如此,我不会做你上面做的.
You can absolutely have a state without a URL. In fact, none of your states need URLs. That's a core part of the design. Having said that, I wouldn't do what you did above.
如果您希望两个状态具有相同的 URL,请创建一个 抽象父状态,为其分配一个 URL,并使其两个状态成为它的子状态(任何一个都没有 URL).
If you want two states to have the same URL, create an abstract parent state, assign a URL to it, and make the two states children of it (with no URL for either one).
这篇关于Angular ui-router:您可以在不更改 URL 的情况下更改状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Angular ui-router:您可以在不更改 URL 的情况下更改状态吗?
基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01