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

2 years ago
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { auth } from "@/middlewares/auth";
import HomeView from "../views/HomePage.vue";
2 years ago
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "home",
component: HomeView,
},
{
path: "/me",
name: "me",
component: () =>
import(/* webpackChunkName: "me" */ "../views/MePage.vue"),
meta: {
2 years ago
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"),
2 years ago
},
];
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();
});
2 years ago
export default router;