如何捕获与angular.js斜线任意数量的网址? [英] How to capture URLs with arbitrary number of slashes in angular.js?
问题描述
我想打一个角部位处理的文件,用户可以在文件系统树中导航,(如在GitHub上: github.com/angular/angular.js/tree/master/path /to/my/file.js
。
I want to make an angular site dealing with files where users can navigate around in a file system tree, (like on github: github.com/angular/angular.js/tree/master/path/to/my/file.js
.
我想捕捉路径/要/我的/ file.js
的URL与角度航线部分:
I would like to capture that path/to/my/file.js
part of the URL with an angular route:
.when("/files/:myPath", templateUrl: "...", controller: "...")
但正如所料,:mypath中
只匹配到下一个斜线
我怎样才能捕捉到的所有剩余部分的网址,包括斜线任意数量的?
How can I capture all remaining parts of the URL, including an arbitrary number of slashes?
我发现 这个问题是相关的,但不同之处在于我的网址是罚款是角散,如后 ... / index.html的#/文件/路径/要/我的/文件
。
I found this question that is related, but differs in that my URL is fine to be after the angular hash, e.g. .../index.html#/files/path/to/my/file
.
推荐答案
由于角1.1.5您可以使用 *路径
- 看到的这里。
As of Angular 1.1.5 you can use *path
- see here.
路径可以包含开始用星命名组( *名称)。所有字符都急切地存储在结果
$ routeParams
以给定名字的时候路由匹配。
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.
例如,例如 /颜色/路线:彩色/大code / *大code /修改将匹配
/色彩/棕色/大code / code /带/ slashs /修改
由于角1.3,语法是:路径*
(信贷德拉克斯在评论)
As of Angular 1.3, the syntax is :path*
(credit to DRAX in the comments)
这篇关于如何捕获与angular.js斜线任意数量的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!