【angular】angualr中实现js跳转路由

前端之家收集整理的这篇文章主要介绍了【angular】angualr中实现js跳转路由前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.引入

import { Router} from '@angular/router';
2.初始化
exportclassHomeComponentimplementsOnInit
    constructor(private router:Router)

    

  ngOnInit()
  

  goNews(){
      //  this.router.navigate(['/news',hero.id]);
      
this. router. navigate([ '../exammode-detail'],{ relativeTo: this. route}

}

3.路由跳转


import{ ExammodeDetailComponent} from './exammode-detail/exammode-detail.component'
export const exammodeRoutes =
[
{ path: 'exammode-detail',component:ExammodeDetailComponent}
]

4.路由跳转的时候也可以带参数

this. router. navigate([ '../questiondetail/'+ j+ "/"+ "ccc"],{ relativeTo: this. route});

在routes.ts中则为

{ path: 'questiondetail/:i/:questionTypeName',component:DetailQuestionComponent}]

猜你在找的Angularjs相关文章