Angular 2 this.router.navigate不起作用

时间:2017-04-05 21:16:52

标签: angular

实际上我在两个数据库请求(post和put)之后尝试从主组件导航到登录组件。它不起作用。

constructor(private service:Service, private router:Router){}

select(solution:string, size:string) {
    let obj1 = {};
    let obj2 = {}

    this.service
      .newObj(obj1)
      .subscribe(
        (data) => {this.service.status(obj2, data._id).subscribe((data) =>**this.router.navigate(['/login'])**);
          console.log('data.id', data._id)},
        error => console.log('Could not post data.'));
  }

1 个答案:

答案 0 :(得分:4)

我认为您打算浏览网址段'登录',然后您应该使用navigateByUrl代替:

this.router.navigateByUrl('/login')