在角UI路由器URL prePEND可选属性 [英] Prepend optional attribute in angular ui-router URL
本文介绍了在角UI路由器URL prePEND可选属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让在UI路由器的URL的开头可选属性?如果是这样,怎么样?
Is there a way to have an optional attribute at the beginning of the url in ui-router? If so, how?
我要实现某事像这样:
.state('events',{
url: '(/city:)?/events/:id'
...
})
所以城市将是可选的。
感谢您因任何输入。
推荐答案
这可能是不好的做法,有两个单独的路径指向同一个状态,但没有什么是让你从创建使用相同的分辨率两种不同的状态/控制器/模板。
It's probably bad practice to have two separate routes point to the same state, but nothing is keeping you from creating two different states that use the same resolutions/controller/template.
$stateProvider
.state('state1', {
url: "/:city/events/:id",
templateUrl: "partials/events.html",
controller: eventsCtrl
})
.state('state2', {
url: "/events/:id",
templateUrl: "partials/events.html",
controller: eventsCtrl
});
function eventsCtrl($scope){
// shared controller
}
同样,这可能是不好的做法,但我想不出一个更好的解决方案
Again, this is probably bad practice but I can't think of a better solution
这篇关于在角UI路由器URL prePEND可选属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文