DEV Community

Cover image for Angular Routing in 5 Minutes: A Minimal, Clear Example
Paccony
Paccony

Posted on

Angular Routing in 5 Minutes: A Minimal, Clear Example

No APIs, no forms, no state. Just routing. A clean, step-by-step demo for anyone starting with Angular.

1.In the terminal, type in and make the next components:


**ng generate component home
ng generate component about
ng generate component contact**

Result:
![ ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv91uv6tzty2ithxe9p1.png)


**2.** Configure app-routing.module.ts
typescript

Result:
![ ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7zt550gg3e37d7s95ma.png)


`

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { ContactComponent } from './contact/contact.component';

const routes: Routes = [
  { path: '', component: HomeComponent },
  { path: 'about', component: AboutComponent },
  { path: 'contact', component: ContactComponent }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }`


**3.** Add navigation to app.component.html
html
Enter fullscreen mode Exit fullscreen mode


Home


About


Contact


**4.** Content of pages (minimal but clear)
🏠 home.component.html
html

Enter fullscreen mode Exit fullscreen mode

Home


This is the home page.


Angular routing demo — show content change without refreshing.


</div
ℹ️ about.component.html
html

About


Ova stranica demonstrira Angular routing.


Klik na link → promjena sadržaja.

📞 contact.component.html
html

Contact


Kontakt stranica — treća ruta u aplikaciji.


Routing je osnova svakog SPA-a.




In the end, you should see.


![ ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upyew1fg7y1iwgtvwlx4.png)








Top comments (0)