This commit is contained in:
2025-03-03 13:47:34 +08:00
parent 586727cb99
commit f01f8a174d
16 changed files with 212 additions and 133 deletions

View File

@@ -2,15 +2,14 @@ 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 },
{
path: "/protected",
name: "protected",
component: Protected,
meta: { requiresAuth: true },
path: "/dashboard",
name: "dashboard",
component: () => import("./pages/Dashboard.vue"),
meta: { auth: true },
},
]
@@ -21,10 +20,10 @@ export const router = createRouter({
router.beforeEach((to, from, next) => {
const isLoggedIn = localStorage.getItem("web-isloggedin") === "true"
if (to.meta.requiresAuth && !isLoggedIn) {
if (to.meta.auth && !isLoggedIn) {
loginModal.value = true
next(false)
} else {
next() // 允许访问
next()
}
})