Angular Basics: How to Add Routing

If you’re creating an Angular application with multiple pages, you need to use routing to navigate between them. You can do this by creating a list of routes with a path for each page in the routing module.

You can then route to other pages within an HTML file by using an anchor tag. You can also route to other pages within a TypeScript file, using the router.navigate() method.

4

How to Create a New Page in an Angular Application

First, create a new Angular application. You can also use an existing one. If you are unfamiliar with how to create a new Angular app, you can learn about it along with otherintroductory concepts used in Angular.

How to Navigate Between the Two Pages

You can use routing to navigate from one page to another. You can configure this in a routing file. This example will have one routing file for the entire app, located insrc/app/app-routing.module.ts.

How to Navigate to the New Page in an HTML File

To navigate to a page within an HTML file, use the anchor tag. In the href attribute, add the path that you specified in the routes array.

How to Navigate to the New Page in a TypeScript File

So far, this demo uses standard HTML links to provide navigation. To navigate using TypeScript file instead of the HTML file, you can userouter.navigate().

Creating Multiple Pages in an Angular Application

You can route between multiple pages within an Angular application by using routing. If you have separate components for each page, you can configure paths for your routes within the routing module.

To navigate to another page via an HTML file, use an anchor tag with the href attribute as the routing path to that page. To navigate to another page via a TypeScript file, you can use the router.navigate() method.

Meta AI being used on a laptop and cellphone

If you are building an Angular application, you can utilize Angular directives. These allow you to use dynamic if-statements, for-loops, or other logical operations within the HTML file of a component.

Angular’s directives add additional behavior to parts of your application. Find out how to use the most common and useful directives.

GIMP website on a monitor.

My iPhone does it all, but I still need my dumb phone.

I plugged random USB devices into my phone and was pleasantly surprised by how many actually worked.

Mint Mobile SIM Protection Number Lock with SIM cards on table

Freeing up vital memory on Windows only takes a moment, and your computer will feel much faster once you’re done.

Lose your laptop without this feature, and you’ll wish you had turned it on.

Laptop with code on the screen and books on the table

The key is not to spook your friends with over-the-top shenanigans.

Technology Explained

PC & Mobile