admin管理员组文章数量:1406950
I have a multipage form made using AngularJS and the AngularUI router ui-router. Each step has it's own URL (/step1 -> /step2 -> /step3). At step 2 the form offers the user a choice between 2 options. Depending on which option is selected I want to be able to send the user to one of two states, but no matter which of the two states is selected I want the URL to change to /step3.
I have tried numerous efforts to get this to work including having the two alternative states one as a child of the other (shown below) resulting in only the parent (step-3-a) being shown, and having an abstract parent step (step-3) with the url and then two child steps (step-3-a, and step-3-b) and routing using the onEnter event and a transition. Both of these failed to display the content correctly (the latter kicked the user out to /user/userId).
It must be possible to route in this manor but I can't seem to make it work. Any help or advice would be gratefully received.
Thanks
$stateProvider
.state('form', {
abstract: true,
views: {
...
}
})
.state('user-form', {
url: '/user/:userId',
parent: 'form',
abstract: true,
views: {
...
}
})
.state('step-1', {
parent: 'user-form',
url: '/step1',
data: {
...
},
views: {
...
}
})
.state('step-2', {
parent: 'user-form',
url: '/step2',
data: {
...
},
views: {
...
}
})
.state('step-3-a', {
parent: 'user-form',
url: '/step3',
data: {
...
},
views: {
...
}
})
.state('step-3-b', {
parent: 'step-3-a',
data: {
...
},
views: {
...
}
})
I have a multipage form made using AngularJS and the AngularUI router ui-router. Each step has it's own URL (/step1 -> /step2 -> /step3). At step 2 the form offers the user a choice between 2 options. Depending on which option is selected I want to be able to send the user to one of two states, but no matter which of the two states is selected I want the URL to change to /step3.
I have tried numerous efforts to get this to work including having the two alternative states one as a child of the other (shown below) resulting in only the parent (step-3-a) being shown, and having an abstract parent step (step-3) with the url and then two child steps (step-3-a, and step-3-b) and routing using the onEnter event and a transition. Both of these failed to display the content correctly (the latter kicked the user out to /user/userId).
It must be possible to route in this manor but I can't seem to make it work. Any help or advice would be gratefully received.
Thanks
$stateProvider
.state('form', {
abstract: true,
views: {
...
}
})
.state('user-form', {
url: '/user/:userId',
parent: 'form',
abstract: true,
views: {
...
}
})
.state('step-1', {
parent: 'user-form',
url: '/step1',
data: {
...
},
views: {
...
}
})
.state('step-2', {
parent: 'user-form',
url: '/step2',
data: {
...
},
views: {
...
}
})
.state('step-3-a', {
parent: 'user-form',
url: '/step3',
data: {
...
},
views: {
...
}
})
.state('step-3-b', {
parent: 'step-3-a',
data: {
...
},
views: {
...
}
})
Share
Improve this question
asked Sep 4, 2013 at 10:21
AndrewDAndrewD
4513 silver badges13 bronze badges
1 Answer
Reset to default 5You're doing inheritance wrong. Parents and children should be dot-separated. Your configuration should look like this:
.state('step-3', {
abstract: true,
url: '/step3',
data: {
...
},
views: {
...
}
})
.state('step-3.a', {
data: {
...
},
views: {
...
}
})
.state('step-3.b', {
data: {
...
},
views: {
...
}
})
This way, both child states will reflect the URL of their parent.
本文标签: javascriptAngularJS UIRouter multiple states with same URLStack Overflow
版权声明:本文标题:javascript - AngularJS UI-Router multiple states with same URL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745049245a2639551.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论