执行导航方法后,上一个组件不会消失。我的新组件出现在旧组件的底部。我应该怎么做才能单独显示新的导航组件?当我直接重定向到新组件时,会显示空白视图。为了生成我使用的组件ng g c componentName。
导航:
this.router.navigate(['dashboard'], {relativeTo: this.route});
新组件:
export class DashboardComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
路由器:
const routes: Routes = [
{ path : "dashboard", component : DashboardComponent},
{path : "**", component: PageNotFoundComponent}]
@NgModule({
imports: [RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'})],
exports: [RouterModule]
})
export class AppRoutingModule { }
export const routingComponents =[DashboardComponent, PageNotFoundComponent]
项目结构:
模板
<div class="bg">
<div class="container">
<div class="row">
<div class='col-md-3'></div>
<div class="col-md-6">
<div class="login-box well">
<legend>Sign In</legend>
<div class="form-group">
<input id="username-email" placeholder="E-mail or Username" type="text" [(ngModel)]="username" class="form-control" />
</div>
<div class="form-group">
<input id="password" placeholder="Password" type="text" class="form-control" [(ngModel)]="password"/>
</div>
<div class="input-group">
<div class="checkbox">
<label>
<input id="login-remember" type="checkbox" name="remember" [(ngModel)]="remember"> Remember me
</label>
</div>
</div>
动漫人物
相关分类