hookehuyr

优化授权页跳转逻辑,点击返回按钮时,返回到首页

<!--
* @Date: 2022-08-29 13:55:31
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-08-24 10:52:35
* @FilePath: /front/src/views/auth.vue
* @LastEditTime: 2024-01-20 09:25:06
* @FilePath: /xysBooking/src/views/auth.vue
* @Description: 授权模块
-->
<template>
......@@ -23,6 +23,19 @@ onMounted(() => {
* 其他字符(比如 :;/?:@&=+$,# 这些用于分隔 URI 组件的标点符号),都是由一个或多个十六进制的转义序列替换的。
*/
let raw_url = encodeURIComponent(location.origin + location.pathname + $route.query.href); // 未授权的地址
// 当用户完成授权后,使用 pushState() 方法将授权页面从浏览器历史记录中移除
window.history.pushState(null, '', '/'); // 将授权页面替换为根路径或其他合适的路径
// 在返回按钮被点击时,检测历史记录的变化并进行处理
window.addEventListener('popstate', function(event) {
// 检查当前页面的 URL
if (window.location.pathname === '/auth') {
// 如果当前页面是授权页面,使用 replaceState() 方法将其替换为其他页面
window.history.replaceState(null, '', raw_url); // 替换为其他合适的路径
}
});
// TAG: 开发环境测试数据
const short_url = `/srv/?a=openid&res=${raw_url}`;
location.href = import.meta.env.DEV
......