angularjs - Matching url path with regex in $urlRouterProvider.when() -


based on angular ui-router wiki (https://github.com/angular-ui/ui-router/wiki/url-routing#urlrouterprovider) should possible use regex matching incoming path. how express regex 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 answer. order of when() statements , state definition important.

this works:

$urlrouterprovider     .when('', '/events')     .when('/', '/events')     .when('/results', '/events/results') $stateprovider     .state('events', {     ......     } $urlrouterprovider // needs @ end match other matches     .when('/:eventname', '/events/:eventname') 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -