7

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.

I would like to capture that path/to/my/file.js part of the URL with an angular route:

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

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

How can I capture all remaining parts of the URL, including an arbitrary number of slashes?


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.

Community
  • 1
  • 1
nh2
  • 24,526
  • 11
  • 79
  • 128

1 Answers1

10

As of Angular 1.1.5 you can use *path - see here.

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 like /color/:color/largecode/*largecode/edit will match /color/brown/largecode/code/with/slashs/edit

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

Community
  • 1
  • 1
tungd
  • 14,467
  • 5
  • 41
  • 45
  • 1
    The catch-all was introduced at 1.1.3, but it's all the same, it is only available in the unstable branch. Nice catch @tungd, I didn't know this until now! – Tiago Roldão Jul 30 '13 at 09:02
  • That sounds like it's exactly what I asked for! – nh2 Jul 31 '13 at 04:22
  • 3
    I would like just to make an update for Angular 1.3. You should use :largecode* instead of *largecode – DRAX Aug 26 '14 at 21:49