lgoin到系统后的Angular 2页面刷新

时间:2017-04-24 16:40:25

标签: angular angular2-routing

我只需要在用户登录系统后刷新页面?我在谷歌搜索这个,但我无法找到任何解决方案。请帮忙。

returnUrl:String = '/admin/dashboard';
submitForm(value: any) {
    if (this.myForm.dirty && this.myForm.valid) {
        this.authenticationService.login(this.user).subscribe(
            /* happy path */ respond => {
                // login successful if there's a jwt token in the response
                let user = respond;
                if (user && user.token) {
                    // store user details and jwt token in local storage to keep user logged in between page refreshes
                    localStorage.setItem('currentUser', JSON.stringify(user.token));
                }
                this.toasterService.pop('success', 'SUCCESS', 'You have successfully logged in');
                return this.router.navigate([this.returnUrl]);
            },
            /* error path */ error => {
                this.toasterService.pop('error', this.sharedService.errorMsg, error);
            }
        );
    } else {
        this.toasterService.pop('error', this.sharedService.errorMsg, 'Invalid data submission');
    }
}

导航到admin / dashboard后我想刷新仪表板组件。

1 个答案:

答案 0 :(得分:-1)

这可能无关紧要,但你为什么要这样做呢? 然而,答案就像是

    submitLog(){
//on login service success
    this.document.location = "";
     }

会将您重定向到您的索引页