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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With