🏠 Routing
Create a home page configured with the Angular Router.
Learn routing basics in Angular and the usage of the routerLink
directive in templates.
Steps
Step 1 - Generate a Component
Generate home page component that is loaded by the router.
command line
ng g component home-page
Step 2 - Register it in the Router
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomePageComponent } from './home-page/home-page.component';
const routes: Routes = [
{ path: '', component: HomePageComponent }
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
Step 3 - Navigate with routerLink
Example of a router link with a special CSS class when active.
some.component.html
<a routerLink="/" routerLinkActive="some-css-class">Home page</a>