7

Am setting my routing in the module and i would like to set default route but it fails

This is the routing module

const appRoutes: Routes = [
 { path: 'login', component: LoginComponent, useAsDefault:true }, //returns an error
 {
  path: 'dash',
  redirectTo:"dashboard"
},

{ path: 'reset-password', component: ResetPasswordComponent },
{ path: '',    redirectTo: '/dashboard', pathMatch: 'full'  },
{ path: '**', component: PageNotFoundComponent }
];

The above returns an error of

LoginComponent; useAsD...' is not assignable to type 'Route[]'

What could be wrong

Android coder
  • 123
  • 1
  • 1
  • 7
  • Please have a look at http://stackoverflow.com/questions/37605119/angular2-router-angular-router-how-to-set-default-route – Ha Hoang Feb 10 '17 at 09:32
  • What's wrong ? u have nice and clearlly response of error ;) coz Router didnt have a `useAsDefault` property, check it: https://angular.io/docs/ts/latest/api/router/index/Route-interface.html – Daredzik Feb 10 '17 at 09:44

1 Answers1

19

When using useAsDefault you need to have the parent route and the useAsDefault on the child route you want to appear first. So, No need of useAsDefault, You can simply gives Login As Default Routes.And As I see there is no Imported component for Dashboard so,

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: "/login",
    pathMatch: 'full'
  },
  { path: 'login', component: LoginComponent },
  { path: 'reset-password', component: ResetPasswordComponent },
  { path: '**', component: PageNotFoundComponent }
];
ER.SHASHI TIWARI
  • 917
  • 1
  • 10
  • 25