1. 程式人生 > >【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}]