
Step 1 – Run the following commands from the console to create a component : –
> ng generate component home
Here, ‘home’ is the name of component.
Step 2 – Next, we need to visit /src/app/app-routing.module.ts and add the following code:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component'; // Add this
const routes: Routes = [
{ path: '', component: HomeComponent }, // Add this
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
The home component will load by default when the app loads.