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
Post a Comment