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

一世执手 提交于 2019-12-10 17:16:46

问题


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


回答1:


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




回答2:


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




回答3:


you can use

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


来源:https://stackoverflow.com/questions/18607534/wildcard-named-group-name-not-working-with-routeprovider-angular-js-v1-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!