How to grab arbitrary slash urls in angular.js?

I want to create an angular site for working with files in which users can navigate the file system tree (for example, on github: github.com/angular/angular.js/tree/master/path/to/my/file.js .

I would like to capture part of the path/to/my/file.js url using the angular route:

 .when("/files/:myPath", templateUrl: "...", controller: "...") 

but, as expected :myPath matches only the next slash.

How can I capture all other parts of the url, including an arbitrary number of slashes?


I found this question which is related, but different in that my url comes up after the angular hash, for example. .../index.html#/files/path/to/my/file .

+7
source share
1 answer

Starting with Angular 1.1.5 you can use *path - see here .

a 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.

For example, routes such as / color /: color / largeecode / * largeecode / edit will match / color / brown / largecode / code / s / slashs / ​​change

As with Angular 1.3, the syntax is :path* (DRAX credit in the comments)

+10
source

All Articles