feat: 新增登录跳转逻辑

This commit is contained in:
duanshuwen
2025-11-17 20:52:45 +08:00
parent c990ad7bbc
commit 5e15a55596
6 changed files with 8173 additions and 17 deletions

View File

@@ -10,6 +10,7 @@ const routes = [
path: "/browser",
name: "Browser",
component: () => import("@/views/browser/BrowserLayout.vue"),
meta: { requiresAuth: true },
},
{
path: "/about",
@@ -23,4 +24,17 @@ const router = createRouter({
routes,
});
router.beforeEach((to, _from, next) => {
const token = localStorage.getItem("token");
if (to.meta && (to.meta as any).requiresAuth && !token) {
next({ path: "/" });
return;
}
if (to.path === "/" && token) {
next({ path: "/browser" });
return;
}
next();
});
export default router;