2024-09-17 17:03:13 +02:00
|
|
|
import { createWebHistory, createRouter } from "vue-router";
|
2024-09-17 18:11:42 +02:00
|
|
|
import routes from "./routes";
|
2024-09-17 17:03:13 +02:00
|
|
|
import { useApiStore } from "../stores/api";
|
|
|
|
|
import { usePageStore } from "../stores/page";
|
|
|
|
|
import { getActivePinia } from "pinia";
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(),
|
|
|
|
|
routes,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
|
|
const pinia = getActivePinia();
|
|
|
|
|
const api = useApiStore(pinia);
|
|
|
|
|
const page = usePageStore(pinia);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const res = await api.fetchPageData(to.path);
|
|
|
|
|
|
|
|
|
|
page.page = res;
|
|
|
|
|
next();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
next(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export { router };
|