merge
This commit is contained in:
parent
0667120de5
commit
1089938956
10 changed files with 122 additions and 77 deletions
40
src/router/router.js
Normal file
40
src/router/router.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { createWebHistory, createRouter } from "vue-router";
|
||||
import Home from "../views/Home.vue";
|
||||
import Inspirations from "../views/Inspirations.vue";
|
||||
import { useApiStore } from "../stores/api";
|
||||
import { usePageStore } from "../stores/page";
|
||||
import { getActivePinia } from "pinia";
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: "/",
|
||||
component: Home,
|
||||
},
|
||||
{
|
||||
path: "/inspirations",
|
||||
component: Inspirations,
|
||||
},
|
||||
];
|
||||
|
||||
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 };
|
||||
Loading…
Add table
Add a link
Reference in a new issue