【问题标题】:Angular2 setting default routeAngular2设置默认路由
【发布时间】:2017-02-10 09:26:00
【问题描述】:

我正在模块中设置我的路由,我想设置默认路由但它失败了

这是路由模块

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

以上返回错误

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

可能有什么问题

【问题讨论】:

标签: angular typescript


【解决方案1】:

使用 useAsDefault 时,您需要先出现父路由和子路由上的 useAsDefault。 所以,不需要useAsDefault,你可以简单地把登录作为默认路由。而且我看到仪表板没有导入组件,

const appRoutes: Routes = [
  {
    path: '',
    redirectTo: "/login",
    pathMatch: 'full'
  },
  { path: 'login', component: LoginComponent },
  { path: 'reset-password', component: ResetPasswordComponent },
  { path: '**', component: PageNotFoundComponent }
];

【讨论】:

    猜你喜欢
    • 2016-10-02
    • 2016-07-16
    • 2016-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    相关资源
    最近更新 更多