Pet*_*ker 4 javascript routes angularjs
我试图通过以下代码片段在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
});
Run Code Online (Sandbox Code Playgroud)
示例路径:/#/ something/details/201/1
在调用此url时,它会执行其他方法.我在这做错了什么?提前致谢
在$routeProvider不支持标准正则表达式,但它不支持命名组:
path可以包含以冒号(:name)开头的命名组.当路由匹配时,直到下一个斜杠的所有字符都匹配并存储在给定名称下的$ routeParams中.
path可以包含以星号(*name)开头的命名组.当路由匹配时,所有字符都急切地存储在给定名称下的$ routeParams中.
所以你应该试试
$routeProvider.when('/something/:action/:id/:params/*rest'
哪个会匹配 /#/something/details/201/1/whatever/you/say