feat: 🚀 优化
This commit is contained in:
@@ -29,22 +29,6 @@ const router = createRouter({
|
||||
scrollBehavior: () => ({ left: 0, top: 0 })
|
||||
});
|
||||
|
||||
// 1. 定义获取URL参数的函数
|
||||
function getUrlParam(paramName: any) {
|
||||
// 获取当前页面URL的查询参数部分(如 "?redirect_path=xxx&t=xxx")
|
||||
const searchStr = window.location.search.slice(1);
|
||||
// 将参数按 "&" 分割成数组(如 ["redirect_path=xxx", "t=xxx"])
|
||||
const paramArr = searchStr.split("&");
|
||||
// 遍历数组匹配目标参数
|
||||
for (let item of paramArr) {
|
||||
const [key, value] = item.split("=");
|
||||
if (key === paramName) {
|
||||
return decodeURIComponent(value); // 解码特殊字符,确保内容准确
|
||||
}
|
||||
}
|
||||
return null; // 未找到参数时返回null
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 路由拦截 beforeEach
|
||||
* */
|
||||
@@ -54,8 +38,8 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
// 1.NProgress 开始
|
||||
NProgress.start();
|
||||
let redirect_path = getUrlParam("redirect_path");
|
||||
|
||||
const currentPath = window.location.pathname;
|
||||
console.log(currentPath, "=currentPath=");
|
||||
// 2.动态设置标题
|
||||
const title = import.meta.env.VITE_GLOB_APP_TITLE;
|
||||
document.title = to.meta.title ? `${to.meta.title} - ${title}` : title;
|
||||
@@ -72,11 +56,11 @@ router.beforeEach(async (to, from, next) => {
|
||||
if (ROUTER_WHITE_LIST.includes(to.path)) return next();
|
||||
|
||||
// 如果没有token但是有订阅路由就将订阅路由当参数携带
|
||||
if (!userStore.newUserToken && redirect_path) {
|
||||
if (!userStore.newUserToken && currentPath === "/foundation/subscribe/warehousing/index") {
|
||||
return next({
|
||||
path: LOGIN_URL,
|
||||
replace: true,
|
||||
query: { redirect_path: redirect_path } // 通过query传递参数
|
||||
query: { redirect_path: currentPath } // 通过query传递参数
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user