Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
AngularJS

Route Configuration in AngularJS

Configure when/otherwise routes with $routeProvider in a config block.

Route Configuration in AngularJS — a practical guide to AngularJS route configuration with clear examples you can reuse in real projects.

AngularJS Tutorial Series (51/99). Prefer one article? Read the complete AngularJS tutorial.

Short description

Use templateUrl + controller / controllerAs for each route.

$routeProvider

angular.module('myApp').config(['$routeProvider', function ($routeProvider) {
  $routeProvider
    .when('/', { templateUrl: 'views/home.html', controller: 'HomeCtrl', controllerAs: 'vm' })
    .when('/items/:id', { templateUrl: 'views/item.html', controller: 'ItemCtrl', controllerAs: 'vm' })
    .otherwise({ redirectTo: '/' });
}]);

Leave a reply

Your email address will not be published. Required fields are marked *