在 app.module.ts 中,我加载了 2 个这样的惰性模块
const appRoutes: Routes = [
{ path: 'anonym', loadChildren: './anonym/anonym.module#AnonymModule' },
{ path: 'user', loadChildren: './user/user.module#UserModule', canActivate: [AuthGuard] }
];
在 app.component.html 中,我可以编写一些基本的 html。我的问题 - 有没有办法为我的 UserModule 设置基本 html?我试图创建 user.component.ts 并像在 app.module.ts 中一样加载它
import { UserComponent } from './user.component';
@NgModule({
declarations: [UserComponent],
bootstrap: [UserComponent]
});
但它没有向我展示 user.component.html
在您的用户模块中定义一个带有空路径的基本路径,然后将子路径定义为子路径。
const ROUTES: Routes = [
{
path: '',
component: UsersComponent,
children: [
{
path: '',
pathMatch: 'full',
redirectTo: 'login'
}, {
path: 'login',
component: LoginComponent
}, {
path: 'logout',
component: LogoutComponent
}
]
}
];
在UsersComponent
现在将被用来作为基本成分,如果你导航到刚/users
会重定向到/users/login
路径。
确保您UsersComponent
有一个模板,<router-outlet></router-outlet>
以便子路由。
@NgModule({
imports: [
RouterModule.forChild(ROUTES)
],
exports: [
RouterModule
]
})
export class UsersModule {
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句