// router/router-guards.js import { useHome } from '@/store/home/index.js'; export function setupRouterGuards(router) { router.afterEach((to) => { window.scrollTo(0, 0); // 根据当前路径设置 currentTab const { currentTab } = useHome(); const path = to.path.replace('/', ''); // 如果路径为空或者是根路径,设置为 home if (!path || path === '/') { currentTab.value = 'home'; } else { // 提取主路径(不包含子路径和查询参数) const mainPath = path.split('/')[0]; // 检查是否是我们关心的主要tab之一 if (['home', 'companyprofil', 'businessintroduction'].includes(mainPath)) { currentTab.value = mainPath; } } }); }