2017-04-05 117 views
2

其实我试图从两个数据库请求(post和put)之后从主Component导航到登录组件。它不工作。Angular 2 this.router.navigate不起作用

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.')); 
    } 
+0

是ü得到什么错误? – Aravind

+0

加载资源失败:服务器响应状态为404(未找到) –

+0

3333/node_modules/rxjs/observable/from.js –

回答

4

我认为你打算通过一个URL段,“登录”导航,那么你应该使用navigateByUrl代替:

this.router.navigateByUrl('/login')