9

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?

Diestrin
  • 294
  • 1
  • 4
  • 11

2 Answers2

15

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
lanoxx
  • 12,249
  • 13
  • 87
  • 142
user2524758
  • 272
  • 3
  • 3
4

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

Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
  • Thanks. You can sugest me an idea or how to archive my goal. I just have 2 routes, /login and /!. The /!/:resourcePath is the path to the resource the user want to see, but I dont want to make a /!/path2Fto2Fthe2Fresource because it's to ugly. – Diestrin Oct 02 '12 at 13:53
  • What do you mean saying resource? Is that some data that has its long 'ugly' ID? – Sergei Basharov Oct 03 '12 at 07:57
  • Yea, well, resource is something like a url of a book, or image, my app is a library, but I want to be able to do something like: http://myapp.com/#/!/javascript/basics/JS_01.pdf so I can get this parameter and look at this direction to show it to the user. The user can bookmark this url to be sharable. – Diestrin Oct 05 '12 at 01:44
  • [UI Router](https://github.com/angular-ui/ui-router/wiki/URL-Routing) supports regular expressions in routes, as well as child routes and some other slick functionality. But the slash matching built into Angular may do the job. – JD Smith May 03 '14 at 03:23