首页 > 解决方案 > 角度路由网址问题

问题描述

我只是在练习路由。我只想在点击时显示显示页面,但显示错误

Error: Cannot match any routes. URL Segment: 'dashboard/eCommerce'

这是我的项目结构

在此处输入图像描述

在登录页面上,我使用点击功能来显示这样的其他页面

login(){
    this.router.navigate(['/dashboard/eCommerce']);
}

仪表板路由模块

    import { NgModule } from '@angular/core';
    import { Routes, RouterModule } from '@angular/router';
    
    import { EcommerceComponent } from "./eCommerce/eCommerce.component";
    
    const routes: Routes = [
      {
        path: '',
        children: [
          {
            path: 'eCommerce',
            component: EcommerceComponent,
            data: {
              title: 'eCommerce'
            }
          },
        ]
      }
    ];
    
    @NgModule({
      imports: [RouterModule.forChild(routes)],
      exports: [RouterModule],
    })
    export class DashboardRoutingModule { }

This is my app-routing module

const appRoutes: Routes = [
  {
    path: '',
    component: LoginPageComponent,
    pathMatch: 'full',
  },

    {
    path: 'register',
    component: RegisterPageComponent,
    pathMatch: 'full',
  },
  { path: '', component: FullLayoutComponent, data: { title: 'full Views' }, children: Full_ROUTES, canActivate: [AuthGuard] },
  { path: '', component: ContentLayoutComponent, data: { title: 'content Views' }, children: CONTENT_ROUTES, canActivate: [AuthGuard] },
];

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

export class AppRoutingModule {

}

在应用程序路由模块中,我的登录页面直接打开(意味着它是我的第一页)然后我需要点击登录按钮我需要显示仪表板/电子商务但不知道为什么它显示错误

标签: angular

解决方案


从您的代码中,我看不到路径是如何/dashboard/eCommerce存在的,因为在某处未提及仪表板(通过模块名称隐含地除外)。

你可能想要这个:

const routes: Routes = [
      {
        // This would define the path to be named 'dashboard'.
        path: 'dashboard',
        children: [
          {
            path: 'eCommerce',
            component: EcommerceComponent,
            data: {
              title: 'eCommerce'
            }
          },
        ]
      }
    ];

推荐阅读