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 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

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 is ECMAScript?JavaScriptHow to change perception and behavior of a person for acceptance of new systems?MiscellaneousHow to add Read More Read Less Button using JavaScript?JavaScriptHow to add a new role in WordPress?WordPressHow to set up the local environment and workspace for Angular development?AngularReading Multiple Inputs in SwiftSwiftHow to clean up after a plugin uninstall in WordPress?WordPressHow to modify AutoSave Interval using code in WordPress?WordPressHow to apply style to the first-child using jQuery?jQueryHTML Copyright SymbolHTMLWhat’s the difference between a Framework and a Library?MiscellaneousJavaScript: how to detect a browser using the user agent?JavaScript