Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to do a wildcard (*) routing in Angular js through 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

On calling this url it executes the otherwise method. What am I doing wrong here? Thanks in advance

like image 825
Peter Parker Avatar asked Feb 16 '23 09:02

Peter Parker


2 Answers

The $routeProvider does not support standard regexp but it does support named groups:

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

  • path can contain named groups starting with a star (*name). All characters are eagerly 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

like image 162
Michał Miszczyszyn Avatar answered Feb 18 '23 02:02

Michał Miszczyszyn


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

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

like image 24
Dmitry Paloskin Avatar answered Feb 18 '23 02:02

Dmitry Paloskin