2

What's the correct way of having default substate in new Angular2 Router?

for example I want router

/user

redirects to

/user/profile

like a default substate of user state.

Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176

1 Answers1

2

You can use redirectTo as shown below.

When user tries to navigate to www.domain.com/user because of redirectTo, he will be redirected to www.domain.com/user/profile.

import { Routes,RouterModule } from '@angular/router';

let routes: Routes = [
  { path: '/user', redirectTo: '/user/profile', pathMatch: 'full'},
  { path: '/user/profile', component:somecomponent },  
];

export const routing = RouterModule.forRoot(routes);
micronyks
  • 54,797
  • 15
  • 112
  • 146