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


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';

  imports: [
  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
What are Google Web Stories and How to create them in WordPress?WordPressRelative Length Units in CSSCSSHow to make a UILabel clickable in Swift 5?SwiftContent types in DrupalDrupalThe Types of DatabasesMiscellaneousWordPress: How to find all posts from a custom post type with multiple custom fields values?WordPressHow to get the height and width of an element using JavaScript?JavaScriptHow to change the style for checked radio button or checkboxes using CSS?CSS@forward modules with a prefix in SCSS (Sass)SCSSWhat’s a Strict mode in JavaScript?JavaScriptHow to Create a Backup From Any Database in SQL?SQL/MySQLHow to use @supports rule in CSS?CSS