{"id":40,"date":"2026-07-04T09:29:41","date_gmt":"2026-07-04T09:29:41","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/angular\/04-angular-routing\/"},"modified":"2026-07-04T09:42:48","modified_gmt":"2026-07-04T09:42:48","slug":"04-angular-routing","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/angular\/04-angular-routing\/","title":{"rendered":"Angular Routing \u2014 Navigate Between Pages (Angular 21+)"},"content":{"rendered":"<p><!-- ktg-updated-banner --><\/p>\n<div class=\"ktg-updated-banner\" style=\"margin:0 0 1.25em;padding:0.75em 1em;background:#fefce8;border-left:4px solid #ca8a04;border-radius:4px;\">\n<p><strong>Updated July 4, 2026.<\/strong> Refreshed for Angular 21 and current SEO best practices.<\/p>\n<\/div>\n<p><!-- ktg-series-toc --><\/p>\n<nav class=\"ktg-series-toc\" aria-label=\"Angular tutorial table of contents\" style=\"margin:1.5em 0;padding:1em 1.25em;background:#f8fafc;border:1px solid #e2e8f0;border-radius:8px;\">\n<h2>Table of Contents<\/h2>\n<p>Follow the Angular tutorial series in order:<\/p>\n<ol>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/01-angular-introduction\/\">Lesson 1: Angular Tutorial \u2014 Introduction (2026)<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/02-angular-cli-setup\/\">Lesson 2: Angular CLI Setup \u2014 Create Your First App (Angular 21+)<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/03-angular-components-and-templates\/\">Lesson 3: Angular Components and Templates \u2014 Build Your First UI<\/a><\/li>\n<li><strong aria-current=\"page\">Lesson 4: Angular Routing \u2014 Navigate Between Pages (Angular 21+)<\/strong><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/05-angular-services-di\/\">Lesson 5: Angular Services and Dependency Injection (Angular 21+)<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/06-angular-http-client\/\">Lesson 6: Angular HTTP Client \u2014 Fetch Data from APIs (Angular 21+)<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/07-angular-forms\/\">Lesson 7: Angular Forms \u2014 Reactive Forms and Signal Forms Preview (Angular 21+)<\/a><\/li>\n<li><a href=\"https:\/\/www.kindsonthegenius.com\/angular\/\">\u2190 Back to Angular Tutorial hub<\/a><\/li>\n<\/ol>\n<\/nav>\n<p><!-- ktg-angular-modern --><\/p>\n<div class=\"ktg-angular-modern\" style=\"margin:1.5em 0;padding:1em;background:#eff6ff;border-left:4px solid #2563eb;border-radius:4px;\">\n<h4>Angular 21 Notes<\/h4>\n<p>Angular 21 uses <code>provideRouter(routes)<\/code> in <code>app.config.ts<\/code> and <code>routerLink<\/code> for navigation \u2014 no NgModule router imports required.<\/p>\n<\/div>\n<p>This lesson covers <strong>Angular routing<\/strong> with <code>@angular\/router<\/code> \u2014 how users move between pages in a single-page application without full browser reloads. You will configure routes, link with <code>routerLink<\/code>, read route parameters, and preview lazy-loaded feature modules.<\/p>\n<p><strong>Prerequisites:<\/strong> Lessons 1\u20133 with a local Angular 21 app (routing enabled at <code>ng new<\/code>). <strong>Estimated time:<\/strong> 45\u201355 minutes.<\/p>\n<h4 id=\"why-routing\">1. Why Routing Matters<\/h4>\n<p>SPAs load one HTML shell and swap views in place. Angular Router maps URLs like <code>\/products\/42<\/code> to components, updates the browser history, and supports deep links \u2014 essential for bookmarks, SEO (with SSR), and back-button behavior.<\/p>\n<figure style=\"margin:1.5em 0;text-align:center;\"><img decoding=\"async\" src=\"https:\/\/www.kindsonthegenius.com\/angular\/wp-content\/uploads\/2026\/07\/04-angular-routing-section-1.jpg\" alt=\"Angular SPA navigation with multiple routed pages\" width=\"1200\" height=\"675\" loading=\"lazy\" style=\"max-width:100%;height:auto;border-radius:8px;border:1px solid #dee2e6;\" \/><figcaption style=\"font-size:0.85em;color:#666;margin-top:0.5em;\">Photo by <a href=\"https:\/\/unsplash.com\/@halacious?utm_source=kindsonthegenius&#038;utm_medium=referral\" rel=\"noopener noreferrer\" target=\"_blank\">Hal Gatewood<\/a> on <a href=\"https:\/\/unsplash.com\/?utm_source=kindsonthegenius&#038;utm_medium=referral\" rel=\"noopener noreferrer\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n<h4 id=\"basic-routes\">2. Define Routes in app.routes.ts<\/h4>\n<p>Angular 21 standalone apps define routes in <code>src\/app\/app.routes.ts<\/code>:<\/p>\n<pre><code class=\"language-typescript\">import { Routes } from '@angular\/router';\nimport { Home } from '.\/home\/home';\nimport { About } from '.\/about\/about';\n\nexport const routes: Routes = [\n  { path: '', component: Home, title: 'Home' },\n  { path: 'about', component: About, title: 'About' },\n  { path: '**', redirectTo: '' },\n];\n<\/code><\/pre>\n<p>Register routes in <code>app.config.ts<\/code> with <code>provideRouter(routes)<\/code> (already present if you chose routing at scaffold time).<\/p>\n<figure style=\"margin:1.5em 0;text-align:center;\"><img decoding=\"async\" src=\"https:\/\/www.kindsonthegenius.com\/angular\/wp-content\/uploads\/2026\/07\/04-angular-routing-section-2.jpg\" alt=\"Developer configuring Angular router routes\" width=\"1200\" height=\"675\" loading=\"lazy\" style=\"max-width:100%;height:auto;border-radius:8px;border:1px solid #dee2e6;\" \/><figcaption style=\"font-size:0.85em;color:#666;margin-top:0.5em;\">Photo by <a href=\"https:\/\/unsplash.com\/@florianolv?utm_source=kindsonthegenius&#038;utm_medium=referral\" rel=\"noopener noreferrer\" target=\"_blank\">Florian Olivo<\/a> on <a href=\"https:\/\/unsplash.com\/?utm_source=kindsonthegenius&#038;utm_medium=referral\" rel=\"noopener noreferrer\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n<h4 id=\"router-outlet\">3. router-outlet and routerLink<\/h4>\n<p>Place the outlet where routed components render:<\/p>\n<pre><code class=\"language-html\">&lt;nav&gt;\n  &lt;a routerLink=\"\/\" routerLinkActive=\"active\" [routerLinkActiveOptions]=\"{ exact: true }\"&gt;Home&lt;\/a&gt;\n  &lt;a routerLink=\"\/about\" routerLinkActive=\"active\"&gt;About&lt;\/a&gt;\n&lt;\/nav&gt;\n&lt;router-outlet \/&gt;\n<\/code><\/pre>\n<p>Import <code>RouterLink<\/code> and <code>RouterLinkActive<\/code> in your standalone shell component.<\/p>\n<h4 id=\"route-params\">4. Route Parameters<\/h4>\n<pre><code class=\"language-typescript\">\/\/ routes\n{ path: 'products\/:id', component: ProductDetail }\n\n\/\/ product-detail.ts\nimport { Component, input } from '@angular\/core';\n\n@Component({\n  selector: 'app-product-detail',\n  standalone: true,\n  template: `&lt;h2&gt;Product {{ id() }}&lt;\/h2&gt;`,\n})\nexport class ProductDetail {\n  id = input.required&lt;string&gt;({ alias: 'id' }); \/\/ route param binding (Angular 21+)\n}\n<\/code><\/pre>\n<p>Alternatively use <code>ActivatedRoute<\/code> or the <code>inject()<\/code> API with <code>toSignal(route.paramMap)<\/code> for async param streams.<\/p>\n<h4 id=\"lazy-loading\">5. Lazy Loading (Preview)<\/h4>\n<pre><code class=\"language-typescript\">{\n  path: 'admin',\n  loadComponent: () =&gt; import('.\/admin\/admin').then(m =&gt; m.Admin),\n}\n<\/code><\/pre>\n<p>Lazy routes download code only when visited \u2014 critical for large enterprise apps. We expand this pattern in advanced tutorials on <a href=\"https:\/\/www.munonye.com\/angular-tutorials\/\">munonye.com<\/a>.<\/p>\n<h4 id=\"next\">6. Next Steps<\/h4>\n<p>Continue to <a href=\"https:\/\/www.kindsonthegenius.com\/angular\/05-angular-services-di\/\">Lesson 5 \u2014 Services and Dependency Injection<\/a> to share data and API clients across routed components.<\/p>\n<h4 id=\"faq\">Frequently Asked Questions<\/h4>\n<p><strong>What is Angular Router?<\/strong><br \/>\nThe official routing library for Angular that maps URLs to components and manages navigation inside SPAs.<\/p>\n<p><strong>Do I still need NgModules for routing?<\/strong><br \/>\nNo. Angular 21 uses standalone components with <code>provideRouter<\/code> and <code>loadComponent<\/code> for lazy loading.<\/p>\n<p><!-- ktg-faq-schema --><br \/>\n<script type=\"application\/ld+json\">{\"@context\":\"https:\/\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What is Angular Router?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The official routing library for Angular that maps URLs to components inside SPAs.\"}},{\"@type\":\"Question\",\"name\":\"Do I still need NgModules for routing?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. Angular 21 uses standalone components with provideRouter and loadComponent.\"}}]}<\/script><\/p>\n<p><!-- ktg-lesson-nav --><\/p>\n<nav class=\"ktg-lesson-nav\" aria-label=\"Lesson navigation\">\n<p><strong>Previous:<\/strong> <a href=\"https:\/\/www.kindsonthegenius.com\/angular\/03-angular-components-and-templates\/\">Lesson 3: Angular Components and Templates \u2014 Build Your First UI<\/a><\/p>\n<p><strong>Next:<\/strong> <a href=\"https:\/\/www.kindsonthegenius.com\/angular\/05-angular-services-di\/\">Lesson 5: Angular Services and Dependency Injection (Angular 21+)<\/a><\/p>\n<\/nav>\n<p><!-- ktg-alkademy-cta --><\/p>\n<div class=\"ktg-alkademy-cta\">\n<p><strong>Want live Angular or frontend classes?<\/strong> Join <a href=\"https:\/\/www.alkademy.com\/courses\" target=\"_blank\" rel=\"noopener noreferrer\">Alkademy<\/a> for instructor-led Angular and frontend courses with hands-on projects.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Updated July 4, 2026. Refreshed for Angular 21 and current SEO best practices. Table of Contents Follow the Angular tutorial series in order: Lesson 1: Angular Tutorial \u2014 Introduction (2026) Lesson 2: Angular CLI Setup \u2014 Create Your First App (Angular 21+) Lesson 3: Angular Components and Templates \u2014 Build Your First UI Lesson 4: &#8230; <a title=\"Angular Routing \u2014 Navigate Between Pages (Angular 21+)\" class=\"read-more\" href=\"https:\/\/www.kindsonthegenius.com\/angular\/04-angular-routing\/\" aria-label=\"Read more about Angular Routing \u2014 Navigate Between Pages (Angular 21+)\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":37,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[2],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-angular-tutorials"],"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":3,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/posts\/40\/revisions\/69"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/media\/37"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/angular\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}