Configuring routeProvider in AngularJs

Configuring the $routeProvider :-

In the above example, we have configured the $routeProvider. The $routeProvider is used to create the$route services. The $routeProvider is used to manage the application routes and it’s responsible for updating views and communicate with its controllers as well.

The example code as given below

<script type="text/javascript">
        var app = angular.module("routesApp", ['ngRoute']);
     
        app.config(['$routeProvider',
          function ($routeProvider) {
              $routeProvider.when('/routeURL1', {
                  templateUrl: 'templateURL1',
                  controller: 'routesController'
              }).
              when('/routeURL2', {
                  templateUrl: 'templateURL2',
                  controller: 'routesController'
              }).
              when('/routeURL3', {
                  templateUrl: 'templateURL3',
                  controller: 'routesController'
              }).
              otherwise({
                  redirectTo: '/login'
              });
          }
        ]);
  </script>

Here $routeProvider is used to configured the config () module and passed the $routeProvider as parameter in the config () function.
The $routeProvider is configured with the help of the functions when () and otherwise ().
The when () function take the route URL, template URL and its controllers also.

The otherwise () function take the redirect URL if not exist in the when () functions.

About Blogger

ANIL SINGH

Hey! I am Anil Singh. I am Active Blogger, Writer and Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
http://www.code-sample.com
http://www.code-sample.xyz

    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book