添加登录功能

This commit is contained in:
2025-02-28 16:20:58 +08:00
parent 81706fc48d
commit 28abe1b429
13 changed files with 181 additions and 14 deletions

View File

@@ -1,10 +1,30 @@
import { createWebHistory, createRouter } from "vue-router"
import { loginModal } from "./store/modal"
import Home from "./pages/Home.vue"
import Protected from "./pages/Protected.vue"
const routes = [{ path: "/", component: Home }]
const routes = [
{ path: "/", component: Home },
{
path: "/protected",
name: "protected",
component: Protected,
meta: { requiresAuth: true },
},
]
export const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to, from, next) => {
const isLoggedIn = localStorage.getItem("web-isloggedin") === "true"
if (to.meta.requiresAuth && !isLoggedIn) {
loginModal.value = true
next(false)
} else {
next() // 允许访问
}
})