Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
Angular 10 Nested Routing & Child Routes Example

Angular 10 nested routing & Child Routes example

Posted on October 5, 2020October 18, 2020 By XpertPhp No Comments on Angular 10 nested routing & Child Routes example

Today, we will discuss with you how to configure nested routing using a Router Module and outlet. now we will create an application and add nested routing and navigation for our applications.

you can easily Add nested Routing & Child Routes to your angular application by using our example. we are creating a Simple Route application. so you can see our angular 10 nested routing & Child Routes example.

Read Also: Angular 10 Router Tutorial With Example

Create new angular app

We will create a new angular app using the following command.

1
2
ng new myapp
cd myapp

when you create your application at that time Angular CLI ask you Would you like to add Angular routing? (y/N). If you enter with y for Yes. then the angular router will be automatically configured.

Create a component in angular

Now we need to create three component such as home, about, and contact. So let’s run the following command to create components.

1
ng g c home

1
ng g c category

Create Nested Routes

Now, we will create two nested routes category-create and category-detail.

1
ng g c category/category-create

1
ng g c category/category-detail

Update view file in angular

src/app/app.component.html
In this example, we will create a simple navigation menu using bootstrap. we need to routerLink for redirect the different routes and also add router-outlet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand" routerLink="/">\Angular 10 Router Tutorial With Example</a>
    <div class="collapse navbar-collapse" id="navbarText">
        <ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" routerLink="/">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink="/category">Category</a>
</li>
        </ul>
    </div>
</nav>
<div class="container">
    <router-outlet></router-outlet>
</div>

src/app/home/home.component.html

1
2
3
<h3>Welcome To Home Page</h3>
<p><b>Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups</b></p>
<p>Lorem ipsum, orLorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book. lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.</p>

src/app/category/category.component.html

1
2
3
<h3>Welcome To Category Page</h3>
<a class="btn btn-primary" routerLink="/category/create">Create</a>
<a class="btn btn-primary" routerLink="/category/detail">Detail</a>

src/app/category/category-create/category-create.component.html

1
2
<h3>Welcome To Create Category Page</h3>
<a class="btn btn-primary" routerLink="/category">Back</a>

src/app/category/category-detail/category-detail.component.html

1
2
<h3>Welcome To Category Detail Page</h3>
<a class="btn btn-primary" routerLink="/category">Back</a>

Adding Routing to your Angular 10

src/app/app-routing.module.ts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
  
import { HomeComponent } from './home/home.component';
import { CategoryComponent } from './category/category.component';
import { CategoryCreateComponent } from './category/category-create/category-create.component';
import { CategoryDetailComponent } from './category/category-detail/category-detail.component';
 
  
 
const routes: Routes = [
  {
      path: '',
      component: HomeComponent
  },
  {
      path: 'posts',
      children: [
        {
          path: '',
          component: CategoryComponent
        },
        {
            path: 'create',
            component: CategoryCreateComponent
        },
        {
            path: 'detail',
            component: CategoryDetailComponent
        }
    ]
 
  }
 
];
 
  
 
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
 
})
 
export class AppRoutingModule { }

Run Our Angular Application

Now we will run our Angular application using the below command.

1
ng serve

 

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • Angular 11 Bootstrap 4 Timepicker Example
  • how to install font awesome in angular 10
  • Angular 10 Http Get Example Tutorial
  • How to Create Component in Angular 10
  • Angular 10 Form Validation Example Tutorial
Angular Tags:angular 10 tutorial, angular routing example

Post navigation

Previous Post: Laravel 8 CRUD Operation Example Using Google Firebase
Next Post: Angular 10 Http Get Example Tutorial

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com