如何在angular2中重定向或调用ts文件中的routerlink

时间:2017-02-07 04:59:41

标签: angular

这是角度2路由代码

     <nav>
         <ul class="nav nav-tabs">
        <li role="presentation" class="active"><a routerLink="/dashboard" routerLinkActive="active">Step I</a></li>
        <li role="presentation"> <a routerLink="/faculty" routerLinkActive="active">Step II</a></li>
        <li role="presentation"><a routerLink="/heroes" routerLinkActive="active">Step III</a></li>
        </ul>          
    </nav>
    <router-outlet></router-outlet>

按钮点击事件

clickFunctionEvent(value: any) {
       this.dataService.setFacultyAnswer(JSON.stringify(value)).subscribe(
      tradeshows => {    
        this.data= tradeshows 
        //if data=success then redirect to next routerLink like "/faculty"                  
       },
      error => {console.error('QuestionList:\n\t ' + error);}
    );
}

如果data=success然后重定向到下一个routerLink,例如"/faculty"

所以如何在.ts文件中

how to disable previous routerLink so not allow to go back

提前致谢

1 个答案:

答案 0 :(得分:28)

你使用

 //in your constructor
  constructor(public router: Router){}

//navigation link.
 this.router.navigate(['your-route']);