Тёмный
No video :(

How routing works in angular 

kudvenkat
Подписаться 832 тыс.
Просмотров 28 тыс.
50% 1

In this video we will discuss, How routing works in an angular application.
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
As you have seen in our previous video, there are many small steps that you have to remember, to implement routing correctly in an angular application. Let's quickly recap those steps.
Step 1 : Set base href in index.html.
Step 2 : Import the RouterModule into the application root module AppModule.
Step 3 : Configure the application routes.
Step 4 : Specify where you want the routed component view template to be displayed using the router-outlet directive
Step 5 : Create a navigation menu and tie the configured routes with the menu using the routerLink directive. Optionally, use the routerLinkActive directive to style the current route that is active, so the user knows the page that he is on, in the application.
Now, let's connect all these small steps and see how routing actually works.
1. We have built the "Home" and "Employees" links using the RouterLink directive. The RouterLink directive tells the angular router where to navigate when the respective links are clicked. So for example, when we click on the "Home" link, the angular Router includes '/home' in the URL.
2. When the URL changes the angular router looks for the corresponding route in the route configuration. In this case the URL changed to /home, so the router looks for the home route. We have the 'home' route already configured. In the route configuration, we have specified to use the HomeComponent.
3. So the angular router knows to display the HomeComponent view template, but the question is where should the HomeComponent view template be displayed.
4. At this point, the Angular router looks for the router-outlet directive. The home component view template is then displayed at the location where we have the router-outlet directive. In our case, we placed the router-outlet directive in the root component (AppComponent) because that is the top level component where we want our routed component templates to be displayed.
5. We specified 'app-root' as the selector for the root component (AppComponent). This selector (app-root) is used as a directive in the application host page i.e index.html. So along with the navigation menu HTML that we already have in the root component, the HomeComponent view template is also display in index.html page.
6 . Now when we click on the "Employees" link, Steps 1 to 5 happen in the order specified and the HomeComponent view template is replaced with the EmployeesComponent view template.
Hope you are now able to connect all the dots and have a good understanding of all the small steps of implementing routing in an angular application.
Please note : When configuring routes in our previous video, we imported Routes type from '@angular/router'. If you look at the definition of Routes type, it is actually an array of Route objects. This Routes type is not required for the application to work. Even if we remove the Routes type declaration from appRoutes as shown below, the application routing works exactly the same way as before. However, using it provides us compile time checking if we mis-spell the properties of the Route object.
Notice the type declaration : Routes is removed from appRoutes constant
const appRoutes = [
{ path: 'home', component: HomeComponent },
{ path: 'employees', component: EmployeesComponent },
{ path: '', redirectTo: '/home', pathMatch: 'full' },
{ path: '**', component: PageNotFoundComponent }
];
At the moment routing is implemented in the root AppModule. However, for separation of concerns and maintainability, it is better to implement routing in a separate Routing module and then import that routing module in the AppModule. In our next video, we will discuss how to move routing into a separate routing module.
Text version of the video
csharp-video-tu...
Slides
csharp-video-tu...
Angular CLI Tutorial
• What is Angular CLI
Angular CLI Text articles & Slides
csharp-video-tu...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 11   
@vijaykamble4730
@vijaykamble4730 6 лет назад
you are simply great Venkat ......very clear voice very nice explanation .... Thank you very much...................... Waiting for next videos
@aminebelhaiza9321
@aminebelhaiza9321 4 года назад
best youtuber ever thanx man
@aagebadho6907
@aagebadho6907 3 года назад
@kudvenkat dont we have to include for angular CLI projects as the way we have did in Angular 2 tutorial?
@supertrillo
@supertrillo 6 лет назад
You are great!
@prasuc634
@prasuc634 6 лет назад
I have trouble with understanding routing concept until I saw your videos. Thank you so much. I have a side nav bar in my app, with a group of menu items inside a bootstrap accordion. In this case, active link is not working properly as the menu items are inside a bootstrap accordion. Could you help me to fix this?
@juturisharon3075
@juturisharon3075 6 лет назад
Super sir
@mhraamirali
@mhraamirali 6 лет назад
Please make some videos on ASP.NET core 1.0 or 2.0
@bernadethmaearcigal-tengco2396
Aamir Ali 2.0
@juturisharon3075
@juturisharon3075 6 лет назад
Pls make an vidoe for http request and load model ui on angular
@tender.branson
@tender.branson 6 лет назад
is a component, not directive. Just a little refinement. I enjoy watching your videos, very informative and compact.
@dnyaneshawar1
@dnyaneshawar1 5 лет назад
No bro is directive define in RouterModule (angular.io/api/router/RouterOutlet)
Далее
Implementing routing in separate module in angular
7:20
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 391 тыс.
HOW DID SHE DECIDE TO DO THIS?!
00:27
Просмотров 8 млн
Good APIs Vs Bad APIs: 7 Tips for API Design
5:48
Просмотров 230 тыс.
Liskov: The Liskov Substitution Principle
4:23
Просмотров 21 тыс.
Stored procedures in sql server   Part 18
20:11
Просмотров 1,5 млн
Mastering Chaos - A Netflix Guide to Microservices
53:14
Lazy loading in angular
10:48
Просмотров 134 тыс.
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 391 тыс.