angular - Angular 在路由后不会破坏源组件
问题描述
我正在构建一个 Angular 8 应用程序,它有 2 个组件:LandingComponent、BlogDetailComponent,当然还有主要组件 AppComponent
如下所示,从 LandingComponent 到 BlogDetailComponent 有路由。当我单击博客详细信息锚点时,它成功地将页面重定向到 BlogDetailComponent 但问题是定向页面还包含登录页面信息。像这样;
Landing Page
Blog Detail Content
我很困惑,我期待源页面被破坏并创建目标页面。但我想我错了。有什么帮助吗?
应用组件.html
<html>
<app-landing></app-landing>
</html>
登陆-component.html
...
<li><a routerLink="blog-detail">Landing Page</a></li>
<router-outlet></router-outlet>
...
博客详细组件.html
...
<div>Blog Detail Content</>
...
应用程序路由模块.ts
...
const routes: Routes = [
{ path: 'blog-detail', component: BlogDetailComponent }
];
@NgModule({
declarations: [],
imports: [CommonModule, RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
解决方案
放置<router-outlet></router-outlet>
在app.component.html中,而不是放在landing-component.html中,并创建一个新的路由{ path: '', component: LandingComponent }
来默认加载登陆组件
推荐阅读
- python - 使用 Python 函数创建数据帧切片
- python - 如何在更精细、均匀间距的网格上有效地插入 3D 阵列?
- ruby - 尝试运行已挂载的容器时,如何解决“找不到此类文件或目录”错误?
- python - 如何使用 plotly express 创建热图动画?
- excel - Excel ExportAsFixedFormat 打破循环特定的迭代
- python - 使用 Python 的 Selenium 单击按钮后 HTML 值不会改变
- r - 一列具有不同数量值的数据框
- stomp - 发送到持久地址/队列的 STOMP 消息在重新启动后无法幸存
- javascript - 为什么javascript异步函数不等待firebase.auth方法完成?
- python - Pandas:现有列中具有最大值的新列