1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { App } from "vue";
- import { createRouter, createWebHistory } from "vue-router";
- import { token } from "./pinia";
- const router = createRouter({
- history: createWebHistory(),
- routes: [
- {
- path: "/",
- component: () => import("@/layouts/home.vue"),
- beforeEnter: (to, from, next) => {
- if (token().token) {
- next();
- } else {
- next("/login");
- }
- },
- redirect: "/home",
- children: [
- {
- path: "/home",
- component: () => import("@/layouts/index.vue"),
- },
- {
- path: "/user",
- component: () => import("@/layouts/user.vue"),
- },
- {
- path: "/comments",
- component: () => import("@/layouts/comments.vue"),
- },
- {
- path: "/plate",
- component: () => import("@/layouts/plate.vue"),
- },
- {
- path: "/post",
- component: () => import("@/layouts/post.vue"),
- children: [],
- },
- {
- path: "/newpost",
- component: () => import("@/components/post/newpost.vue"),
- },
- ],
- },
- {
- path: "/login",
- component: () => import("@/layouts/login.vue"),
- beforeEnter: (to, from, next) => {
- if (!token().token) {
- next();
- } else {
- next("/home");
- }
- },
- },
- ],
- });
- export function setupRouter(app: App<Element>) {
- app.use(router);
- }
- export default router;
|