我有一些问题的路由未找到的页面。我使用的是Angular(类型脚本)。在我的应用程序中,我有4个主要的路由:应用程序路由、登录路由、用户路由和管理员路由。我创建了NotFoundComponent,如果添加以下语法:
{ path: '404', component: NotfoundComponent},
{ path: '**', redirectTo:'/404'}
如果我将其添加到UserRouting,当我以admin身份登录时,它会转到404;如果我将其添加到AdminRouting,当我以用户身份登录时,它会转到404;如果我将其添加到AppRouting,当我以用户和管理员身份登录时,它会转到404;我应该做些什么才能让事情正常进行?以下是我的路由代码:
用户路由:
const routes: Routes = [
{ path: 'user-dashboard', component: UserLayoutComponent,
canActivate:[AuthGuard],
children:[
{ path: '', component: UserDashboardComponent},
{ path: 'profilo-user', component: ProfilouserComponent},
{ path: 'preferiti', component: CarrelloComponent},
{ path: 'contatti', component: ContattiComponent},
{ path: 'prodotti-negozio'/*/:id:nome*/, component: ProdottiNegozioComponent}
]},
];
管理路由:
const routes: Routes = [
{ path: 'admin-dashboard', component: AdminLayoutComponent,
canActivate:[AuthGuard], canActivateChild:[AuthGuard], children:[
{ path: '', component: AdminDashboardComponent},
{ path: 'profilo-admin', component: ProfiloadminComponent},
{ path: 'users', component: UsersComponent},
{ path: 'work-in-progress', component: WorkInProgressComponent}
]},
];
AppRouting:
const routes: Routes = [
{ path: '', redirectTo:'/login', pathMatch: 'full' },
{ path: '404', component: NotfoundComponent},
{ path: '**', redirectTo:'/404'}
];
登录路由:
const routes: Routes = [
{ path:'login', component: LoginComponent }
];
我该怎么做才能让它正常工作?
1条答案
按热度按时间jk9hmnmh1#
您的路由是如何连接的?也许您应该在一个地方列出它们以简化路由逻辑?例如: