Aurelia 推送状态应用程序在登录和注销时重新加载
Aurelia Push State App Reload on Login and Logout
使用 Aurelia 和 Visual Studio 配置推送状态时,我遇到了一个奇怪的行为,在我 select 登录后,我的整个应用程序重新加载,而不是路由器只是推送到主页。当我注销时也会发生这种情况,我进入登录屏幕并刷新整个应用程序。我正在使用 Aurelia Auth。如有任何帮助,我们将不胜感激。
我想我前一段时间遇到了完全相同的问题,这是我切换回 pushState = false
的原因之一(但我的信息可能对你有帮助)。
无论如何,以下问题描述了我所面临的问题:https://github.com/paulvanbladel/aurelia-auth/issues/55
问题是,插件在内部设置了 href:
登录 - https://github.com/paulvanbladel/aurelia-auth/blob/master/src/authentication.js#L95-L99
if (this.config.loginRedirect && !redirect) {
window.location.href = this.getLoginRedirect();
} else if (redirect && isString(redirect)) {
window.location.href = window.encodeURI(redirect);
}
注销 - https://github.com/paulvanbladel/aurelia-auth/blob/master/src/authentication.js#L139-L143
if (this.config.logoutRedirect && !redirect) {
window.location.href = this.config.logoutRedirect;
} else if (isString(redirect)) {
window.location.href = redirect;
}
您需要做的是避免这两种情况,即将 loginRedirect
和 logoutRedirect
设置为空字符串 (''
)。然后,像我在 GH 问题的示例中所做的那样,通过 Aurelias 路由器自行导航:
return this.auth.login(userInfo)
.then(response => {
console.log('You signed in successfully.');
this.router.navigate('/contents');
})
当然,在您的注销方法上执行相同的路由器导航。
使用 Aurelia 和 Visual Studio 配置推送状态时,我遇到了一个奇怪的行为,在我 select 登录后,我的整个应用程序重新加载,而不是路由器只是推送到主页。当我注销时也会发生这种情况,我进入登录屏幕并刷新整个应用程序。我正在使用 Aurelia Auth。如有任何帮助,我们将不胜感激。
我想我前一段时间遇到了完全相同的问题,这是我切换回 pushState = false
的原因之一(但我的信息可能对你有帮助)。
无论如何,以下问题描述了我所面临的问题:https://github.com/paulvanbladel/aurelia-auth/issues/55
问题是,插件在内部设置了 href:
登录 - https://github.com/paulvanbladel/aurelia-auth/blob/master/src/authentication.js#L95-L99
if (this.config.loginRedirect && !redirect) {
window.location.href = this.getLoginRedirect();
} else if (redirect && isString(redirect)) {
window.location.href = window.encodeURI(redirect);
}
注销 - https://github.com/paulvanbladel/aurelia-auth/blob/master/src/authentication.js#L139-L143
if (this.config.logoutRedirect && !redirect) {
window.location.href = this.config.logoutRedirect;
} else if (isString(redirect)) {
window.location.href = redirect;
}
您需要做的是避免这两种情况,即将 loginRedirect
和 logoutRedirect
设置为空字符串 (''
)。然后,像我在 GH 问题的示例中所做的那样,通过 Aurelias 路由器自行导航:
return this.auth.login(userInfo)
.then(response => {
console.log('You signed in successfully.');
this.router.navigate('/contents');
})
当然,在您的注销方法上执行相同的路由器导航。