Search code examples
angularjsangularjs-routing

how to use a single controller for multiple routes


how to assign a couple of controller and view to multiple route patterns in AngularJS? for example I have a couple of view and controller:

{
  templateUrl: '/partial/single-item.html',
  controller: 'SingleItemController'
}

witch I want them for two routes:

/car/:id
/bike/:id

Solution

  • You can have a route like : /:myRoute/:id And test in the controller(or in a route regex) the value of myRoute for example