Monday, May 20, 2024
Angular 10Bootstrap 4.5

Angular 10 Dynamic Routing Working Tutorial

Hello friends, welcome back to my blog. Today in this blog post, I am going to tell you, Angular 10 Dynamic Routing Working Tutorial.

Angular 10 Dynamic Routing

Angular10 came and if you are new then you must check below two links:

  1. Angular10 for beginners
  2. Angular10 Basic Tutorials

Friends now I proceed onwards and here is the working code snippet for Angular 10 Dynamic Routing Working Tutorial and please use carefully this to avoid the mistakes:

1. Firstly friends we need fresh angular 10 setup and for this we need to run below commands but if you already have angular 10 setup then you can avoid below commands. Secondly we should also have latest node version installed on our system:

Guys, you can skip this step if you already have angular 10 fresh setup:

npm install -g @angular/cli 

ng new dynamicrouting //Create new Angular Project

cd dynamicrouting // Go inside the Angular Project Folder

ng serve --open // Run and Open the Angular Project

http://localhost:4200/ // Working Angular Project Url

2. Now friends we need to run below commands to generate components users and userdetails:

ng g component users

ng g component userdetails

ng serve --o


3. Now friends we need to add below code into your src/app/app.module.ts file:

import { Routes, RouterModule } from '@angular/router';
const appRoutes: Routes = [
  { path: 'user', component: UsersComponent },
  { path: 'user-detail/:id', component: UserdetailsComponent },

  imports: [
      { enableTracing: true } // <-- debugging purposes only


4. Now friends we need to add below code into src/app/app.component.html file:

<link rel="stylesheet" href="">
 <div class="jumbotron text-center">
<nav class="navbar navbar-expand-sm bg-light">
  <ul class="nav nav-pills">
    <li class="nav-item"><a class="nav-link" routerLink="/">Home</a></li>
    <li class="nav-item"><a class="nav-link" routerLink="/user">users</a></li>

<div class="container-fluid">


For bootstrap styling, I have directly added bootstrap cdn but we can add it right also and for that you can follow this :- Add Bootstrap in Angular

5. Now friends we need to add below code into src/app/users/users.component.html file:

<ul class="nav nav-pills">
  <li class="nav-item"><a class="nav-link" routerLink="/user-detail/1">user1</a></li>
  <li class="nav-item"><a class="nav-link" routerLink="/user-detail/2">user2</a></li>


6. Now friends we need to add below code into src/app/userdetails/userdetails.component.html file:

<h2> User No: {{id}}</h2>


7. Now friends we need to add below code into src/app/userdetails/userdetails.component.ts file:

import { Component, OnInit } from '@angular/core';
import {Router, ActivatedRoute, Params} from '@angular/router';
  selector: 'app-userdetails',
  templateUrl: './userdetails.component.html',
  styleUrls: ['./userdetails.component.css']
export class UserdetailsComponent implements OnInit {

  constructor(private activatedRoute: ActivatedRoute) {}
  public id: string;
  ngOnInit() {

     // Note: Below 'queryParams' can be replaced with 'params' depending on your requirements = this.activatedRoute.snapshot.paramMap.get('id');



Now we are done friends. If you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad.



the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.