【发布时间】:2020-12-07 15:04:32
【问题描述】:
我正在构建一个 Angular 8 应用程序,它有 2 个组件:LandingComponent、BlogDetailComponent,当然还有主要组件 AppComponent
如下所示,有从 LandingComponent 到 BlogDetailComponent 的路由。当我单击博客详细信息锚时,它成功地将页面重定向到 BlogDetailComponent 但问题是定向页面还包含登录页面信息。像这样;
Landing Page
Blog Detail Content
我很困惑,我希望源页面被销毁并创建目标页面。但我想我错了。有什么帮助吗?
app-component.html
<html>
<app-landing></app-landing>
</html>
登陆组件.html
...
<li><a routerLink="blog-detail">Landing Page</a></li>
<router-outlet></router-outlet>
...
blog-detail-component.html
...
<div>Blog Detail Content</>
...
app-routing-module.ts
...
const routes: Routes = [
{ path: 'blog-detail', component: BlogDetailComponent }
];
@NgModule({
declarations: [],
imports: [CommonModule, RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
【问题讨论】:
-
将
放在app.component.html中而不是放在landing-component.html中,新建路由{ path: '', component: LandingComponent } 默认加载登陆组件 -
它工作了@Abhijit 我还从 app-component.html 中删除了
以便所有方向都基于路线文件。谢谢你。如果您添加为答案。我会批准的。 -
你修好了它,添加为答案????
标签: angular angular-ui-router angular8