---
title: "What is routing in AngularJS?"  
description: "What is routing in AngularJS?"  
author: "Ashutosh Patel"  
published: 2024-06-19  
updated: 2024-06-19  
canonical: https://www.mindstick.com/interview/33918/what-is-routing-in-angularjs  
category: "angular js"  
tags: ["javascript", "angular js", "angularjs routing"]  
reading_time: 2 minutes  

---

# What is routing in AngularJS?

#### AngularJS Routing

**Routing** in AngularJS allows developers to manage different **views** (or pages) in a **single page application** (**SPA**). This is facilitated by the `ngRoute` module, where routes are configured using `$routeProvider`. Each method features a template and controller, and provides seamless navigation without full page reloads, thereby enhancing user experience and application responsiveness.

## Example-

Here is a simple example to demonstrates the using of routing in angular js,

```javascript
angular.module('myApp', ['ngRoute'])
 .config(function($routeProvider) {
   $routeProvider
     .when('/home', {
       templateUrl: 'views/home.html',
       controller: 'HomeController'
     })
     .when('/about', {
       templateUrl: 'views/about.html',
       controller: 'AboutController'
     })
     .otherwise({ redirectTo: '/home' });
 });
```

## In the example above-

The route `/home` maps to `views/home.html` and HomeController.

The route `/about` maps to `views/about.html` and AboutController.

If none of the specified routes match, the `otherwise` method specifies a **default** route.

**Also, Read:** [What is built-in services in AngularJS?](https://www.mindstick.com/interview/33917/what-is-built-in-services-in-angularjs)

## Answers

### Answer by Ashutosh Patel

#### AngularJS Routing

**Routing** in AngularJS allows developers to manage different **views** (or pages) in a **single page application** (**SPA**). This is facilitated by the `ngRoute` module, where routes are configured using `$routeProvider`. Each method features a template and controller, and provides seamless navigation without full page reloads, thereby enhancing user experience and application responsiveness.

## Example-

Here is a simple example to demonstrates the using of routing in angular js,

```javascript
angular.module('myApp', ['ngRoute'])
 .config(function($routeProvider) {
   $routeProvider
     .when('/home', {
       templateUrl: 'views/home.html',
       controller: 'HomeController'
     })
     .when('/about', {
       templateUrl: 'views/about.html',
       controller: 'AboutController'
     })
     .otherwise({ redirectTo: '/home' });
 });
```

## In the example above-

The route `/home` maps to `views/home.html` and HomeController.

The route `/about` maps to `views/about.html` and AboutController.

If none of the specified routes match, the `otherwise` method specifies a **default** route.

**Also, Read:** [What is built-in services in AngularJS?](https://www.mindstick.com/interview/33917/what-is-built-in-services-in-angularjs)


---

Original Source: https://www.mindstick.com/interview/33918/what-is-routing-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
