DEV Community

Atit Patel
Atit Patel

Posted on • Originally published at js.plainenglish.io on

How to Send data through routing paths in Angular

Daily Angular Tips, Tricks, and Best Practices: Part 9

As a developer, there is no limit to learning. We always need to be up to date with technologies as well as the upcoming or current features which are trending in the market.

Photo by Ben White on Unsplash

Recently, I was looking for the best techniques to write clean and optimize my angular code. I have gone through a lot of articles, and as we know, it is limitless. Then I thought of consolidating the checklist with different Basic Angular Topics which helped me and might help others too in the future.

These small articles not only help you to write a better and clean Angular Code but also clear the concepts of front-end technologies. This will help you to build your strong base and can help you in the upcoming frontend interviews.

Let’s move towards our main discussion.

Passing data between components is one of the common tasks which we do in frontend development. Sometimes when we don’t have state maintained in our application we can use the angular router feature to pass the data between the components.

We can achieve this like this using @angular/routerwhich does support the route state and navigationExtras, which takes an object literal similar to queryParams

Let’s checkout different approaches to achieve this functions.

1. Using Required Routing Parameters:

2. Using Route Optional Parameters:

3. Using Route Query Parameters:

4. Using Route NavigationExtras

It’s always better to see practicals instead of theory. No issue. I have a practical example ready for you. Check out here.

https://stackblitz.com/edit/angular-route-parameters-tu8g9e

If you missed previous parts checkout below:

What is the difference between constructor and ngOnInit?

Explain how Angular application loads/Initialize.

Explain the digest cycle/Change detection Cycle in Angular.

What is the difference between declarations, providers, and imports?

What is the difference between BehaviourSubject, Subject, ReplaySubject and Async Subject?

How To Detect Changes When An Angular Component Is Using ‘@input’

Top comments (0)