未捕获(承诺):错误:无法匹配任何路线.URL 段:角度 [英] Uncaught (in promise): Error: Cannot match any routes. URL Segment: Angular

查看:32
本文介绍了未捕获(承诺):错误:无法匹配任何路线.URL 段:角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Angular 的新手.我正在使用 Angular 7 并进行简单的路由.登录页面后,我想显示一个主页.登录是 app-root 组件的一部分,在主页中我显示 headersidenav 但我无法路由到主页.

I am new to Angular. I am using Angular 7 and doing a simple routing. After Login page, I want to display a home page. Login is a part of app-root component and in home page I am showing header and sidenav but I am not able to route to home page.

app-routimg.module.ts

const appRoutes: Routes = [
  {
    path: '',
    loadChildren: './login/login.module#LoginModule'
},
  {
    path: 'dashboard',
    loadChildren: './dashboard/dashboard.module#DashBoardModule',

}
];
  @NgModule({
    imports: [RouterModule.forRoot(appRoutes)],
    exports: [RouterModule],
   // providers: [AuthGuard]
}

dashboard-routing.modul.ts

const appRoutes: Routes = [
  {
    path: 'dashboard',
    component: DashBoardComponent ,
    children: [
         {
             path: '',
            redirectTo: 'home'
        },
        {
            path: 'home',
            loadChildren: './home/home.module#HomeModule'
        },

    ]
}
];
@NgModule({
  imports: [
    RouterModule.forChild(appRoutes)
  ],
  exports: [
    RouterModule
  ]
})

login.component.ts

onSubmit() {

       this._router.navigate(['/home']);
      }
}

core.js:15724 错误错误:未捕获(承诺):错误:无法匹配任何路线.URL 段:'home' 错误:无法匹配任何路由.网址段:'家'

core.js:15724 ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'home' Error: Cannot match any routes. URL Segment: 'home'

推荐答案

在你的dashboard-routing-module.ts中应该是这样的:

it should be like this in your dashboard-routing-module.ts:

const routes: Routes = [{
  path: '',
  component: DashBoardComponent,
  children: [
   {
      path: '',
      redirectTo: 'home',
      pathMatch: 'prefix'
   },
   {
      path: 'home',
      component: HomeComponent
   }
 ]
}];

这篇关于未捕获(承诺):错误:无法匹配任何路线.URL 段:角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆