Angular 6 References/ Router


This is the documentation for Angular 6.
You can switch to the latest version Angular 10.

A routed Angular application has one singleton instance of the Router service. When the browser's URL changes, that router looks for a corresponding Route from which it can determine the component to display.

Pass array of routes to the RouterModule.forRoot method in the module imports to configure the router.

const appRoutes: Routes = [
  { path: 'home', component: HomeComponent },
  { path: 'contacts', component: ContactsComponent },

  imports: [
export class AppModule { }


Only call RouterModule.forRoot in the root module. In any other module, you must call the RouterModule.forChild method to register additional routes.

const blogRoutes: Routes = [
  { path: 'blog',  component: BlogComponent },
  { path: 'blog/post/:id', component: BlogPostComponent }

  imports: [
  exports: [
export class BlogRoutingModule { }
Links & Tutorials