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-2026 CODEPRJ.COM