Navigation is the process of moving from one page to another. In any web app, you will have many screens/pages, and you will have to navigate to those pages.
1. RouterLink - HTML
2. Method (navigate, navigateByUrl) - TypeScript
In Angular, you don't use href to navigate. Angular provides few ways to navigate (RouterLink)
RouterLink is basically an Angular Directive (remember Directives gives super powers to our HTML)
HTML
TypeScript Method
<a routerLink="/profile" class="btn btn-primary">See Profile</a>
<a (click)="navigateToProfile()" class="btn btn-primary">See Profile</a>
navigateToProfile() {
this.router.navigateByUrl('profile');
}
App-routing.module.ts
const routes: Routes = [
{ path: "", component: LandingPageComponent },
{ path: "login", component: LoginComponent },
{ path: "signup", component: SignupComponent },
{ path: "dashboard", component: DashboardComponent },
{ path: 'customers', loadChildren: () => import('./customers/customers.module').then(m => m.CustomersModule) },
{ path: "**", redirectTo: "" },
];
All Child routes are displayed where this directive is written <router-outlet> </router-outlet>
All routes that inherit will be displayed where the directive router-outlet is
some quote
Module is a collection of different components (usually with a similar functionality).
Creating a new module
This will create a module and add its route to app.module
Now, there are two ways to set up routes.
1. component.
2. Lazy Loaded module.