Files
webpreview/src/router.ts
2025-03-20 18:58:41 +08:00

48 lines
1.1 KiB
TypeScript

import { createWebHistory, createRouter } from "vue-router"
import { loginModal } from "./store/modal"
import Home from "./pages/Home.vue"
import { STORAGE_KEY } from "./utils/const"
const routes = [
{ path: "/", name: "home", component: Home },
{
path: "/submissions/:page",
name: "submissions",
component: () => import("./pages/Submissions.vue"),
},
{
path: "/dashboard",
name: "dashboard",
component: () => import("./pages/Dashboard.vue"),
meta: { auth: true },
children: [
{
path: "tutorial/:display",
name: "tutorial",
component: () => import("./pages/Markdown.vue"),
},
{
path: "user-manage/:page",
name: "user-manage",
component: () => import("./pages/UserManage.vue"),
},
],
},
]
export const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to, from, next) => {
const isLoggedIn = localStorage.getItem(STORAGE_KEY.LOGIN) === "true"
if (to.meta.auth && !isLoggedIn) {
loginModal.value = true
next(false)
} else {
next()
}
})