AngularJS - Route - How to match star (*) as a path

本秂侑毒 提交于 2020-01-19 06:00:47

问题


I'm making a resource viewer app, but the problem is that i tried to match when("/!/:resourceUrl").

It works fine if the resource url is something like /path, but how can I make something like a /path/to/the/resource.
I don't know how much paths will it take, so I can't do .when("/!/:path1/:path2/:path3").

Any ideas?


回答1:


As of angular-1.2 you can do this:

when("/!/:resourceUrl*")

http://code.angularjs.org/1.2.0/docs/api/ngRoute.$routeProvider

In particular the documentation gives the following example:

For example, routes like /color/:color/largecode/:largecode*\/edit will match /color/brown/largecode /code/with/slashs/edit and extract:

  • color: brown
  • largecode: code/with/slashs



回答2:


As of now, AngularJS doesn't support regular expressions in routes.

Check these links: https://github.com/angular/angular.js/issues/918, https://github.com/angular/angular.js/pull/972



来源:https://stackoverflow.com/questions/12685085/angularjs-route-how-to-match-star-as-a-path

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