Routing in AngularJS is used when the user wants to navigate to different pages in an application but still wants it to be a single page application. AngularJS routes enable the user to create different URLs for different content in an application. The ngRoute module helps in accessing different pages of an application without reloading the entire application.
$routeProvider is used to configure the routes. It helps to define what page to display when a user clicks a link. It accepts either when() or otherwise() method.
The ngRoute must be added as a dependency in the application module:
Example 1: This example describes the AngularJS Routing by implementing the “when” method that specifies the new route definition to the $route service.
Example 2: This example describes the AngularJS Routing by the “Otherwise” method is used with the “when” method, where the otherwise() method is used to set the route definition to change the route when no route definition is matched.
Please Login to comment...