即使状态更改后,URL也不会更改.ui-router [英] URL is not changing even after the state is changed . `ui-router`
问题描述
我正在使用 ui-router
和状态提供程序来路由应用程序中的页面.我在状态提供程序中编写了以下状态.
.state('home',{网址:"/home",templateUrl:"public/msStream/stateFiles/stateHome.html",控制器:"stateHomeController"}).state('home.profile',{网址:"/home/profile",templateUrl:"public/msStream/views/setting/ProfileBody.html"})
当我处于 home
状态时.我的URL中添加了/home
,但是当我使用 $ state.go("home.profile)
切换到 home.profile
状态时,我的URL并没有更改为/home/profile
,但是在相同状态的 templateurl
中添加的HTML页面已经呈现在最前面.
我尝试在州的URL中添加/profile
和/home/profile
,但似乎没有任何效果.我在这里想念什么?
我创建了此处工作的插栓器
父子状态确实继承了很多东西.除其他外, url
.因此,我们不应将来自父母的网址部分用于孩子.
$ stateProvider.state('home',{网址:"/home",templateUrl:"public/msStream/stateFiles/stateHome.html",控制器:"stateHomeController"}).state('home.profile',{//这里//代替这个//网址:"/home/profile",//我们需要这个网址:"/profile",templateUrl:"public/msStream/views/setting/ProfileBody.html"})
注释也很重要-父项必须包含其子项的anchor/target/ui-view:
public/msStream/stateFiles/stateHome.html
< div>< h2>这是家</h2>儿童的占位符:< hr/>< div ui-view ="></div></div>
这里最重要的是 < div ui-view ="></div>
-子视图的占位符(未命名)>
在运行中进行检查此处
I am using ui-router
and state provider to route the pages in my application. I have following states written in state provider.
.state('home', {
url: '/home',
templateUrl: 'public/msStream/stateFiles/stateHome.html',
controller: 'stateHomeController'
})
.state('home.profile', {
url: '/home/profile',
templateUrl: 'public/msStream/views/setting/ProfileBody.html'
})
When I am in home
state. /home
is added in my URL, but when I switch to home.profile
state using $state.go("home.profile)
, my URL is not changing to /home/profile
but HTML page added in templateurl
of the same state is getting rendered on front.
I tried adding /profile
and /home/profile
in the URL of the state but nothing seems to work. What am I missing here?
I created working plunker here
The paren-child states do inherit a lot. Among other things, also the url
. So we should not use for child the url part coming from parent.
$stateProvider
.state('home', {
url: '/home',
templateUrl: 'public/msStream/stateFiles/stateHome.html',
controller: 'stateHomeController'
})
.state('home.profile', {
// HERE
// instead of this
// url: '/home/profile',
// we need this
url: '/profile',
templateUrl: 'public/msStream/views/setting/ProfileBody.html'
})
Also very improtant note - parent must contain anchor/target/ui-view for its child:
public/msStream/stateFiles/stateHome.html
<div>
<h2>this is the home</h2>
placeholder for child:
<hr />
<div ui-view=""></div>
</div>
The most important here is the <div ui-view=""></div>
- a placeholder for child view (unnamed)
Check it in action here
这篇关于即使状态更改后,URL也不会更改.ui-router的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!