加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular2设置默认路由

发布时间:2020-12-17 06:51:35 所属栏目:安全 来源:网络整理
导读:我在模块中设置我的路由,我想设置默认路由,但它失败了 这是路由模块 const appRoutes: Routes = [ { path: 'login',component: LoginComponent,useAsDefault:true },//returns an error { path: 'dash',redirectTo:"dashboard"},{ path: 'reset-password',co
我在模块中设置我的路由,我想设置默认路由,但它失败了

这是路由模块

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[]'

可能有什么不对

解决方法

使用useAsDefault时,您需要在要首先显示的子路由上使用父路由和useAsDefault.
所以,不需要使用AsDefault,你可以简单地给Login As Default Routes.And,因为我看到没有为Dashboard导入的组件,所以,

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读