In an Angular project, how to create a separate routing file for the project?

When using Angular Cli to create a project, if you do not add any suffix parameters, the generated project will have no routing module by default. So, how to make the created Angular project have a routing module/routing file?

 

Two ways:

 

1 When creating the project at the very beginning, bring the parameters:

 

--routing=true|false

 

 

2 If you have already created the project and do not want to delete the existing project, and re-create the project, use the command to generate the module to create the routing file, but you need to add some parameters:

 

ng generate module app-routing --flat --module=app

 

Among them: --flat means to put the generated files at the top of the project, instead of creating a separate directory; --module=app tells the CLI to register the created routing file in the AppModule root module, that is, the name of the class of the routing file Put it in the imports array of AppModule.

 

 

Reference: https://www.jianshu.com/p/7619ab2cadd7

https://angular.cn/cli/generate#module

Guess you like

Origin blog.csdn.net/ZxxSteven/article/details/114263284