Wildcard * named group (: name *) does not work with $ routeProvider Angular js v1.0.6

I am trying to perform wildcard (*) routing in Angular js through the following code snippet:

$routeProvider.when('/something/:action/:id/:params*\/', { templateUrl : "/js/angular/views/sample/index.html", controller : 'SampleCtrl' }).otherwise({ redirectTo: '/something/all' //This exists in real code }); 

sample path: / # / something / details / 201/1

When this url is called, it executes another method. What am I doing wrong here? thanks in advance

+4
source share
3 answers

$routeProvider does not support standard regex but supports named groups:

  • the path may contain named groups starting with a colon (: name). All characters up to the next slash are mapped and stored in $ routeParams with the given name when the route matches.

  • a path can contain named groups starting with a star (* name). All characters are readily stored in $ routeParams under the given name when the route matches.

So you should try

$routeProvider.when('/something/:action/:id/:params/*rest'

which will match /#/something/details/201/1/whatever/you/say

+6
source

As far as I know, angular do not support regular expressions. You should look at angular ui-router.

https://github.com/angular-ui/ui-router

+2
source

you can use

 $routeProvider.when('/something/:action/:id/:params?, 
0
source

Source: https://habr.com/ru/post/1500452/


All Articles