You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB
TypeScript

import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { auth } from "@/middlewares/auth";
import HomeView from "../views/HomePage.vue";
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "home",
component: HomeView,
},
{
path: "/me",
name: "me",
component: () =>
import(/* webpackChunkName: "me" */ "../views/MePage.vue"),
meta: {
requireAuth: true,
},
},
{
path: "/user/:id",
name: "user",
meta: {
allowEmbed: true,
},
component: () =>
import(/* webpackChunkName: "user" */ "../views/UserPage.vue"),
},
{
path: "/auth",
name: "auth",
component: () =>
import(/* webpackChunkName: "auth" */ "../views/AuthPage.vue"),
},
{
path: "/auth/callback",
name: "authCallback",
component: () =>
import(/* webpackChunkName: "authCallback" */ "../views/AuthCallbackPage.vue"),
},
];
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
});
router.beforeEach(async (to, from, next) => {
if (!to.name) next("/");
else if (to.meta?.requireAuth) auth({ to, from, next, router });
else next();
});
export default router;