feat: 新增登录跳转逻辑
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user