Setting up a Component Router

A Component Router is not part of the core Angular framework. It comes as part of the Angular NPM bundle as an individual library, @angular/router. We need to add @angular/router to the packages.json under the dependencies section. Then, in the app.routing.ts, we need to import Routes and RouterModule from @angular/router. The router constitutes directives such as RouterOutlet, RouterLink, and RouterLinkActive, a service RouterModule and the configuration for Routes.

Then, we need to add the <base> element under <head> to instruct the router to set up navigation URLs. The following code snippet shows the <base> tag with the href attribute that is to be added to the head tag in the index file, considering that the app folder is the root of the application. This is required when you run your application in HTML5 mode. It helps resolve all the relative URLs in the application:

<base href="/"> 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.53.209