Angular入门(四) Router 替换当前页面

1.在 xx.html 中直接 写标签
      <a [routerLink]="['/home']">home</a>
 
2.在 xx.html 中 触发click事件
  <button class="btn btn-primary" (click)="Login()">Submit</button>
   在xx.ts中 
       引入路由
           import { Route, Router, ActivatedRoute, Params } from '@angular/router';
      export 注入
  constructor(private route: ActivatedRoute, private router: Router) { }
      export 写 Login()函数
        Login(){

  this.router.navigate(['../home'],{relativeTo:this.route});//跳转到定义好的home 页面
}

原文地址:https://www.cnblogs.com/zhuzy/p/8033200.html