首页 > 解决方案 > Angular 默认路由器插座

问题描述

我有用户模块,我正在尝试加载默认路由器插座。当路径为 /user 但它不起作用时,我想加载 UserHomeComponent 。如果我添加路径而不是将其保持为空,则它可以正常工作。这是我的用户路由模块:

const routes:Routes = [
    {path: 'user' ,  component: UserComponent , children:[
        {path: '' , component: UserHomeComponent},
        {path: 'new-request' , component: NewRequestComponent},
        {path: 'checkout' , component: CheckoutComponent},
        {path: 'edit-info' , component: UserEditInfoComponent},
        {path: 'requests', component: UserRequestsComponent},
        {path: 'change-password' , component: UserChangePasswordComponent},
        {path: 'delete-account' , component: DeleteAccountComponent}
    ]}
]

这是我的应用路由模块:

const appRoutes:Routes = [
    {path: '' , redirectTo: 'login' , pathMatch: 'full'},
    {path: 'login' , component: LoginComponent },
    {path: 'signup' , component: SignupComponent},
    {path: 'user' , loadChildren: () => import('./user/user.module').then(m => m.userModule)},];

标签: angularpathdefaultrouteroutlet

解决方案


加载一个 UserHomeComponent,改变这个

{path: 'user' ,  component: UserComponent , children:[

经过

{path: '' ,  component: UserComponent , children:[

推荐阅读