Android coder
Android coder

Reputation: 123

Angular2 setting default route

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

Upvotes: 7

Views: 24037

Answers (1)

ER.SHASHI TIWARI
ER.SHASHI TIWARI

Reputation: 917

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 }
];

Upvotes: 19

Related Questions