Home > Back-end >  I use angular router and can't use path:'**' for 404 page
I use angular router and can't use path:'**' for 404 page

Time:07-02

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:

CodePudding user response:

Can you try with

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

CodePudding user response:

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
  },
  • Related