(的https:/ /github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider )应该是可以使用正则表达式匹配传入路径。我怎么能前preSS正则表达式来匹配以下重定向规则:
$ urlRouterProvider 。当('','/事件') 。当('/','/事件') 。当('/:eventName的','/事件/:eventName的') 。当('/结果','/事件/结果)
测试例如:
本地主机= GT;本地主机/#/事件本地主机/ = GT;本地主机/#/事件本地主机/ myEvent =>本地主机/#/事件/ myEvent本地主机/结果= GT;本地主机/#/事件/结果本地主机/#/事件= GT;本地主机/#/事件本地主机/#/结果= GT;本地主机/#/结果
解决方案
我找到了答案。当在()语句和状态定义的顺序是非常重要的。
本作品:
$ urlRouterProvider 。当('','/事件') 。当('/','/事件') 。当('/结果','/事件/结果)$ stateProvider .STATE('事件',{ ...... }$ urlRouterProvider //这需要在年底以匹配所有其他比赛 。当('/:eventName的','/事件/:eventName的')
Based on the angular ui-router wiki (https://github.com/angular-ui/ui-router/wiki/URL-Routing#urlrouterprovider) it should be possible to use regex for matching the incoming path. How could I express regex to match following redirection rules:
$urlRouterProvider
.when('', '/events')
.when('/', '/events')
.when('/:eventName', '/events/:eventName')
.when('/results', '/events/results')
Test example:
localhost => localhost/#/events
localhost/ => localhost/#/events
localhost/myEvent => localhost/#/events/myEvent
localhost/results => localhost/#/events/results
localhost/#/events => localhost/#/events
localhost/#/results => localhost/#/results
解决方案
I found the answer. Order of the when() statements and the state definition is important.
This works:
$urlRouterProvider
.when('', '/events')
.when('/', '/events')
.when('/results', '/events/results')
$stateProvider
.state('events', {
......
}
$urlRouterProvider // This needs to be at the end to match all other matches
.when('/:eventName', '/events/:eventName')