Registering routing in the app module - lordoftheflies/angular-essential-training GitHub Wiki
With a list of app routes created in the app.routing.ts file, the next step is to let the app module know about them. You may have noticed that we have not added a router module to the app module up to this point, which is different from, say, the forms module and HTTP module. That's because the router module is designed to be used to set up multiple route configurations. It has a static class method available called for Root, that returns an object of type module with providers. This object contains exported directives and providers as well as a configured router and is intended for the app root module. The router module is located in the angular router scoped package so we can add router module to the list of imports at the top. And then below the app routes, we can add an export of a variable named routing and set that equal to a call to RouterModule.forRoot. For Root expects an array of route objects so we pass that the app route's variable. The for Root method will take these routes and set up the router for us, getting it ready for use in the app root module. The final thing we need to do is head over to the app.module.ts file and add an import statement for the routing. Then add routing to the imports array in the NgModule decorator metadata. With that, our app module is aware of the routes we set up and is ready to start processing them. It is also set up to use the router module directives and services that come from the router module. But configuring and registering routes is just part of the routing story. I'll cover the other parts in the next few videos.