3.1 动态路由的js跳转

  1. 1.在路由中配置动态路由
  2. path:'productcontent/:pid',
  3. 2.配置相对应的事件
  4. <button (click)="goProductcontent()">js跳转路由</button>
  5. 3.导入路由跳转模块
  6. import { Router } from '@angular/router'
  7. 4.声明(实例化)
  8. constructor(public router:Router) { }
  9. 5.跳转
  10. goProductcontent(){
  11. this.router.navigate(['/productcontent/','1234'])
  12. }

3.2 js普通跳转

  1. 1.配置相对应的事件
  2. <button (click)="gohomes()">js跳转路由</button>
  3. 2.导入路由跳转模块
  4. import { Router } from '@angular/router'
  5. 3.声明(实例化)
  6. constructor(public router:Router) { }
  7. 4.跳转
  8. gohomes(){
  9. this.router.navigate(['/homes'])
  10. }