【发布时间】:2013-10-30 19:50:40
【问题描述】:
我需要使用 angular-ui 路由器将一个段的路由解析为不同的行为。
例如我这样做:
$stateProvider
.state('parent', {
url: '/:route'
template: '<div ui-view/>'
controller: ['$scope', '$state', '$stateParams', ($scope, $state, $stateParams)->
# I get the type of route that the user is visiting checking server side and returning its type..
switch typeOfRoute
when "user"
$state.transitionTo('parent.user.profile')
when "place"
$state.transitionTo('parent.place.page')
else
alert("bad route")
]
})
.state('parent.user', {
abstract: true
template: '<div ui-view/>'
})
.state('parent.user.profile', {
template: '<h1>This is a profile</h1>'
controller: ['$scope', '$state', '$stateParams', ($scope, $state, $stateParams)->
# Here happens all about the user
]})
.state('parent.place', {
abstract: true
template: '<div ui-view/>'
})
.state('parent.place.page', {
template: '<h1>This is a place</h1>'
controller: ['$scope', '$state', '$stateParams', ($scope, $state, $stateParams)->
# Here happens all about the place
]})
如果有人访问,使用上面的示例:
/Johndoe -> 返回该路由是一个用户并转换到 parent.user.profile /Newyork -> 返回该路线是一个地点并转换到 parent.place.page
使用这种方法的问题是,当我编写解决 /Johndoe/likes 的路线时,浏览器再次转到 /Johndoe,我正在考虑检查参数的长度等......但也许有人做了类似的事情并且更好。
有人试图构建类似的东西吗?我卡在这一点上。
非常感谢!!
【问题讨论】:
标签: html angularjs angular-ui angular-ui-router