我使用Angular路由器,可以使用路径:' **'对于404页

发布于 2025-02-12 04:25:17 字数 733 浏览 1 评论 0原文

export const AppRoutes: Routes = [
  {path: '', redirectTo: 'dashboard', pathMatch: 'full'},
  {path: 'login', component: LoginComponent},
  {path: 'register', component: RegisterComponent},
  {
    path: '',
    component: FullComponent,
    canLoad: [LoginGuard],
    children: [
      {
        path: '',
        loadChildren: () => import('./material-component/material.module').then(m => m.MaterialComponentsModule)
      },
      {path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)}
    ]
  },
  {path: '**', component: PageNotFoundComponent}
];

但是404页面只能匹配:'/a''/b'无法匹配:'/a/b''/c/d'

我认为'''''''''''''''''''''''''''' >

export const AppRoutes: Routes = [
  {path: '', redirectTo: 'dashboard', pathMatch: 'full'},
  {path: 'login', component: LoginComponent},
  {path: 'register', component: RegisterComponent},
  {
    path: '',
    component: FullComponent,
    canLoad: [LoginGuard],
    children: [
      {
        path: '',
        loadChildren: () => import('./material-component/material.module').then(m => m.MaterialComponentsModule)
      },
      {path: 'dashboard', loadChildren: () => import('./dashboard/dashboard.module').then(m => m.DashboardModule)}
    ]
  },
  {path: '**', component: PageNotFoundComponent}
];

but 404 page can only match: '/a' '/b' can't match: '/a/b' '/c/d'

I think the '' url is not correct with childen:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天煞孤星 2025-02-19 04:25:18

您的问题是,您的代码应该看起来像这样。

{
    path: 'material',
    loadChildren: () => import('./material-component/material.module').then(m => m.MaterialComponentsModule)
  },

以及在MaterialComponentRountingModule中

{
    path: '',
    component:MaterialComponent
  },

You're right the problem is that.Your code should look like this .

{
    path: 'material',
    loadChildren: () => import('./material-component/material.module').then(m => m.MaterialComponentsModule)
  },

And in the MaterialComponentRountingModule

{
    path: '',
    component:MaterialComponent
  },
与他有关 2025-02-19 04:25:17

你能尝试吗

{ path: '**', pathMatch: 'full', component: PageNotFoundComponent },

Can you try with

{ path: '**', pathMatch: 'full', component: PageNotFoundComponent },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文