javascript - 通配符 * 命名组 ( :name*) not working with $routeProvider Angular js v1. 0.6

标签 javascript angularjs routes

我正在尝试通过以下代码片段在 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/

相关文章:

javascript - 如何重构代码以避免全局范围?

javascript - React 如何跳转到表单中的目标输入区域?

javascript - ES6 多重继承?

javascript - 最好的 Javascript 下拉菜单?

javascript - 如何让 Angular 指令等待隔离范围数据可用?

javascript - 如何使用 asp.net mvc 制作大 Angular 单页应用程序?

routes - model 和 setupController 钩子(Hook)与未定义的模型

ruby-on-rails - Rails 4 路由错误 : No Route Matches [POST]

angularjs - 使用Angular-DataTables更新数据时,将重置分页

java - 使用 guice servlet 将请求路由到匹配页面