最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

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

Share Improve this question asked Sep 4, 2013 at 7:10 Peter ParkerPeter Parker 3881 gold badge4 silver badges12 bronze badges 1
  • 1 Named group (wild cards *) are supported for version 1.2 and on-wards. I was trying for 1.0.4 – Peter Parker Commented Nov 20, 2013 at 17:56
Add a ment  | 

3 Answers 3

Reset to default 6

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

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

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

you can use

$routeProvider.when('/something/:action/:id/:params?,
发布评论

评论列表(0)

  1. 暂无评论