Skip to main content

Posts

Showing posts with the label how add route in default module in angular

how add route in default module in angular

Add the  AppRoutingModule In Angular, the best practice is to load and configure the router in a separate, top-level module that is dedicated to routing and imported by the root  AppModule . By convention, the module class name is  AppRoutingModule  and it belongs in the  app-routing.module.ts  in the  src/app  folder. Use the CLI to generate it. ng generate module app - routing -- flat -- module = app import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; @NgModule({ imports: [ CommonModule ], declarations: [] }) export class AppRoutingModule { } import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { HeroesComponent } from './heroes/heroes.component'; const routes: Routes = [ { path: 'heroes', component: HeroesComponent } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule ...