Angular 2 - 成功登录后重定向不起作用

Angular 2 - Redirect after successful login not working

我有一个方法 "authenticate" 让我登录。我真的不知道它是否有效,因为我使用虚拟登录,只是为了测试路由和返回日期。 这种方法的问题是,在成功登录后,我应该被重定向到 Actuals 页面,目前该页面不起作用。

authenticate(username, password) {
var creds = JSON.stringify({ UserName: username.value, UserPassword: password.value, SetDebug: true});
var headers = new Headers();
headers.append('Content-Type', 'application/json');

      this.http.post('http://demo/aariworx5/api/login/login', creds ,{headers: headers})
          .subscribe(
          res => {
              this.data = res.json();
              this.router.parent.navigate('/Actuals');
          },
          error => console.log(error)
          );
  }
}

我得到的错误如下:类型错误:无法读取未定义的 属性 'parent'。从我读到的内容中我可以猜到这个页面不是实际页面的父页面。我已经在另一个 post 中尝试了这个建议: this.router.parent.navigate(['/Actuals']); 那是在 post: 这在我的情况下不起作用,不知道为什么...

您需要注入路由器才能使其可用

constructor(private:Router router) {}