角UI基于路由的URL路径+散路径 [英] Angular ui route based on URL path + hash path
问题描述
我试图使用UI路由器显示以下路径不同的模板。我加入了完整的URL,所以你可以清楚地看到的意图是什么。
基本上我希望路由器占实际的URL路径,但现在没有模板被检测和状态提供重定向到 /
代替。
的http://本地主机/仪表板/#家园
而这正是进入到 $ stateProvider
。
.STATE('dashboard.home',{
网址:'/家,
路径:仪表盘,
templateUrl:'/谐音/仪表板/家
})
我创建 plunker用实例这里。在一般情况下,我们可以有父子是这样的:
$ stateProvider
.STATE(仪表盘,{
模板:'<格UI视图=>< / DIV>,
})
$ stateProvider
.STATE('dashboard.home',{
网址:'/ HOME2',
路径:仪表盘,
templateUrl:'/谐音/仪表板/家
})
我们可以看到,有一个父状态仪表盘(定义在这种情况下,没有URL),并有其子dashboard.home',这URL这里是网址:'/ HOME2
。所以要#/ HOME2,我们会达到这个境界
或者我们可以使用这样的:
$ stateProvider
.STATE('dashboard_home',{
网址:'/家,
templateUrl:'/谐音/仪表板/家
})
这是一个没有父母的状态。这就是为什么它不能包含仪表
,这将作为评估:找到名称仪表盘家长
当点击这个链接,这些国家正在努力:
< A HREF =#/家>
&所述; A HREF =#/ HOME2>
检查一下这里
I'm trying to use the UI router to display a different template for the following path. I'm adding the full URL so you can see exactly what the intention is.
Basically I want the router to account for the actual URL path, but right now no template gets detected and the state provider redirects to /
instead.
http://localhost/dashboard/#home
And this is what goes in to the $stateProvider
.
.state('dashboard.home', {
url: '/home',
path: 'dashboard',
templateUrl: '/partials/dashboard/home'
})
I created plunker with example here. In general, we can have parent child like this:
$stateProvider
.state('dashboard', {
template: '<div ui-view=""></div>',
})
$stateProvider
.state('dashboard.home', {
url: '/home2',
path: 'dashboard',
templateUrl: '/partials/dashboard/home'
})
What we can see, there is a parent state 'dashboard' (in this case without url defined) and there is its child 'dashboard.home', which url here is url: '/home2'
. So going to #/home2, we will reach this state
Or we can use this:
$stateProvider
.state('dashboard_home', {
url: '/home',
templateUrl: '/partials/dashboard/home'
})
This is state without a parent. That's why it cannot contain dashboard.
, which would be evaluated as: "find parent with name 'dashboard'"
And these states are working when clicked this link:
<a href="#/home">
<a href="#/home2">
Check it here
这篇关于角UI基于路由的URL路径+散路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!