JHipster:登录成功后如何重定向到另一个页面?

时间:2018-03-21 14:22:36

标签: authentication redirect login jhipster

尝试更改JHipster默认应用程序网关的默认行为,我正在寻找重定向到自定义login_success.html页面的正确方法。是否有任何官方教程或解决方法?

我通过编辑 login.component.ts 中的登录功能,尝试如下但没有任何反应;甚至没有错误:

login() {
    this.loginService.login({
        username: this.username,
        password: this.password,
        rememberMe: this.rememberMe
    }).then(() => {
        this.authenticationError = false;
        this.activeModal.dismiss('login success');
        if (this.router.url === '/register' || (/^\/activate\//.test(this.router.url)) ||
            (/^\/reset\//.test(this.router.url))) {
            this.router.navigate(['']);
        }

        this.eventManager.broadcast({
            name: 'authenticationSuccess',
            content: 'Sending Authentication Success'
        });

        // // previousState was set in the authExpiredInterceptor before being redirected to login modal.
        // // since login is succesful, go to stored previousState and clear previousState
        // const redirect = this.stateStorageService.getUrl();
        const redirect = '/something.html';
        console.log('Before Redirect');
        if (redirect) {
            console.log('Redirect');
            this.stateStorageService.storeUrl(null);
            // this.router.navigate([redirect]);
            this.router.navigateByUrl(redirect);
        }
    }).catch(() => {
        this.authenticationError = true;
    });
}

1 个答案:

答案 0 :(得分:4)

在login.component.ts中找到:

        // // previousState was set in the authExpiredInterceptor before being redirected to login modal.
        // // since login is succesful, go to stored previousState and clear previousState
        const redirect = this.stateStorageService.getUrl();
        if (redirect) {
            this.stateStorageService.storeUrl(null);
            this.router.navigate([redirect]);
        }

并改为:

        // // previousState was set in the authExpiredInterceptor before being redirected to login modal.
        // // since login is succesful, go to stored previousState and clear previousState
        const redirect = this.stateStorageService.getUrl();
        if (redirect) {
            this.stateStorageService.storeUrl(null);
            this.router.navigate([redirect]);
        } else {
            this.stateStorageService.storeUrl(null);
            this.router.navigate(['/panel']);
        }

其中'/ panel'是您要重定向的页面。