我正在尝试通过以下代码片段在 Angular js 中执行通配符 (*) 路由:
$routeProvider.when('/something/:action/:id/:params*\/', {
templateUrl : "/js/angular/views/sample/index.html",
controller : 'SampleCtrl'
}).otherwise({
redirectTo: '/something/all' //This exists in real code
});
示例路径:/#/something/details/201/1
调用此 url 时,它会执行 otherwise 方法。我在这里做错了什么? 提前致谢
最佳答案
$routeProvider
不支持标准正则表达式,但它支持命名组:
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.
所以你应该试试
$routeProvider.when('/something/:action/:id/:params/*rest'
这将匹配 /#/something/details/201/1/whatever/you/say
关于javascript - 通配符 * 命名组 ( :name*) not working with $routeProvider Angular js v1. 0.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18607534/