角UI路由器:您可以更改状态不改变网址? [英] Angular ui-router: Can you change state without changing URL?
问题描述
的多重嵌套的意见的的 UI路由器
的功能是非常好的 - 你可以很容易地从一个的状态跳你的应用程序到另一个。
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,但有时并非如此。我觉得这个概念的状态的应该是独立/从可选的路由的
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,显示我的意思。这是plunkers之一叉子在 UI路由器
文档,用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"
}
}
})
这似乎工作 - 网址保持不变。再次,有多少多余的工作都是在这里完成?这是获得认可/测试使用?
This seems to work - the URL stays the same. Again, how much redundant work is done here? Is this an approved/tested usage?
这将是很好,如果你可以省略网址
从状态..
It would be nice if you could omit the url
from a state..
更新的问题:这是获得认可/测试使用
Update question: Is this an approved/tested usage?
推荐答案
您绝对可以有一个状态,没有一个网址。事实上,没有你的国家需要的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,创建一个<一个href=\"https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nested-Views#abstract-states\">abstract父状态,指定一个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).
这篇关于角UI路由器:您可以更改状态不改变网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!