Possible Duplicate:
AngularJS - Route - How to match star (*) as a path
How do I specify wildcards in my routes -
$routeProvider
.when('/admin/*', {
templateUrl: 'admin.html',
controller: 'AdminCtrl'
})
So the above should work for /admin/users and /admin/users/1 or /admin/org/3. So there could be either one or two levels of path after admin. How do I do it ?
A Wildcard route has a path consisting of two asterisks (**). It matches every URL, the router will select this route if it can't match a route earlier in the configuration. A Wildcard Route can navigate to a custom component or can redirect to an existing route.
The two asterisks, ** , indicate to Angular that this routes definition is a wildcard route. For the component property, you can define any component in your application.
Using below wild card we can define page not found route D.
Nested routes are routes within other routes. In this tutorial, we will show you how to create a child route and display the child components. The Angular allows us to nest child routes under another child routes effectively creating a Tree of routes.
Currently AngularJS does not support regular expression in routes.
You can workaround as follows
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/admin', {templateUrl: 'admin.html', controller: 'AdminCtrl'})
.when('/admin/:type', {templateUrl: 'admin.html', controller: 'AdminCtrl'})
.when('/admin/:type/:id', {templateUrl: 'admin.html', controller: 'AdminCtrl'});
}]);
http://plnkr.co/edit/tBumW2oEqki2sEl1hjSc?p=preview
IMO, it is good idea to have the separate controller for both admin and users, unless otherwise you have some special requirement.
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