Redirecting the Router to Another Route

When your application starts, it navigates to the empty route by default.We can configure the router to redirect to a named route by default:

  1. export const routes: Routes = [
  2. { path: '', redirectTo: 'component-one', pathMatch: 'full' },
  3. { path: 'component-one', component: ComponentOne },
  4. { path: 'component-two', component: ComponentTwo }
  5. ];

The pathMatch property, which is required for redirects, tells the router how it should match the URL provided in order to redirect to the specified route. Since pathMatch: full is provided, the router will redirect to component-one if the entire URL matches the empty path ('').

When starting the application, it will now automatically navigate to the route for component-one.

原文: https://angular-2-training-book.rangle.io/handout/routing/redirects.html