angular - 只有在 app-routing.module.ts 中路由时,组件才使用主布局
问题描述
如果我使用 another-routing.module.ts 路由我的组件,那么它不会使用 mainlayout。
MainComponent 对我来说就像 app.component.ts ,从下面的链接中得到了这个想法。因为我想绕过登录页面的 MainLayout。 如何在 Angular 2 中为登录组件使用单独的布局?
App-routing.module.ts
const routes: Routes = [
{path: "", component: MainComponent,
children: [
{ path: "", component: DashboardComponent },
{ path: "help", component: HelpComponent }
]
}
];
another-routing.module.ts
const routes: Routes = [
{path: 'users' , children : [
{path: 'add', component: UsersComponent},
]}
];
解决方案
布局组件应该有一个 router-outlet 标签,并且你的模块应该加载到布局组件中。
const routes: Routes = [{
path: '',
component: LayoutComponent,
children: [
{
path: 'companies',
loadChildren: () =>
import('./pages/companies/companies.module').then(m => m.CompaniesModule)
},
{
path: '**',
redirectTo: 'companies'
}
]
}];
这样,布局组件的所有子级都将继承布局组件。
推荐阅读
- javascript - 为什么这个嵌套请求没有在带有 Spotify API 的 Node.js 中运行?
- python - 当参数之一不在范围内时,在主函数中运行函数的最佳方法
- kubernetes - 微服务活跃度和就绪超时处理
- python - 带有 scipy.optimize.linprog 的拉格朗日乘数
- java - 如何删除消防基地数据库中的一项?
- flutter - 当用户在 Flutter 中提供错误数据时如何显示错误
- java - Java 是否支持用 Java 编写的输入法?
- python - 安装和导入 tensorflow 和 keras
- gatsby - Netlify CMS 基于主题森林主题构建
- javascript - 如何在反应渲染中使用 calc css 函数