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 頁面
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM