Yogesh Chauhan's Blog

How to add AppRoutingModule in Angular application using command line?

in Angular on October 3, 2020

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

Where

flat puts the file in src/app instead of its own folder.

module=app tells the CLI to register it in the imports array of the AppModule.

The generated file looks like this:


import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: []
})
export class AppRoutingModule { }

Credit: Angular.io


Most Read

#1 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 How to uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
The 8 Golden Rules of Programming I Have Learned in My CareerMiscellaneousWhat is Prototypal Inheritance in JavaScript?JavaScriptCan We Use For Loop to Loop Through Associative Arrays in PHP?PHP3 ways to pass a variable in url() function in SCSS (Sass)SCSSHow to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?PHPContent Blocks in SCSS (Sass)SCSSVariables and Distance Functions in SCSS (Sass)SCSSHow to get the full URL of current page in PHP?PHPIs there a difference between SCSS and Sass?SCSSCreate dynamic selectors using SCSS (Sass)SCSSWhat is a “promise” in JavaScript?JavaScriptHow to create a flip pricing table using CSS and JavaScript?CSS