15

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 ?

Community
  • 1
  • 1
murtaza52
  • 46,887
  • 28
  • 84
  • 120

1 Answers1

23

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.

venkat
  • 2,310
  • 1
  • 15
  • 15
  • 1
    [UI Router](https://github.com/angular-ui/ui-router/wiki/URL-Routing) supports regex in routes, among other cool things. – JD Smith May 03 '14 at 03:25