Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 202
Diestrin Avatar asked Oct 02 '12 05:10

Diestrin


People also ask

What is path match in Angular?

pathMatch = 'prefix' tells the router to match the redirect route when the remaining URL begins with the redirect route's prefix path. Ref: https://angular.io/guide/router#set-up-redirects. pathMatch: 'full' means, that the whole URL path needs to match and is consumed by the route matching algorithm.

How do we set a default route in $routeProvider?

Creating a Default Route in AngularJS The below syntax just simply means to redirect to a different page if any of the existing routes don't match. otherwise ({ redirectTo: 'page' }); Let's use the same example above and add a default route to our $routeProvider service. function($routeProvider){ $routeProvider.

What is use of $routeProvider in AngularJS?

We use $routeProvider to configure the routes. The config() takes a function that takes the $routeProvider as a parameter and the routing configuration goes inside the function. The $routeProvider is a simple API that accepts either when() or otherwise() method. We need to install the ngRoute module.

How do I check Angular routes?

Steps to get current route URL in Angular. Import Router,NavigationEnd from '@angular/router' and inject in the constructor. Subscribe to the NavigationEnd event of the router. Get the current route url by accessing NavigationEnd's url property.


1 Answers

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
like image 146
user2524758 Avatar answered Oct 02 '22 12:10

user2524758