2016-12-15 93 views
0

后代码路由我知道,使用routerLink指令,我能够路由到一个目的地:angular2:可观察的成功

<a [routerLink]=" ['/app'] ">LogOut</a> 

这是建立在您的网站链接的静态方法。

public createAccount():void { 
    this.clearAlerts(); 
    this.commty.create(this.form.value.mail, this.form.value.passwd) 
    .subscribe(
     (result: any) => {  // <-- handler for result 
      >>>>>>>>>> go to '/app' route <<<<<<<<<<<<<<< 
     }, 
     (error: any) => {  // <-- handler for error 
      this.addAlert(error.message); 
     } 
    ); 
} 

我想一定有办法做到这一点使用打字稿代码... 你能提供给我:

尽管如此,有时路线必须根据如果http请求已经被正确处理完成一个例子或任何文件?

回答

2
router.navigate(['/app']) 

但对于它,你需要在部件导入和注入Router

import {Router}  from '@angular/router'; 
import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: '<h1>Hello</h1>', 
}) 
export class AppComponent { 
    constructor(private router: Router){ 
    router.navigate(['/app']) 

    } 
}