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}]