52 lines
1.6 KiB
JavaScript
Vendored
52 lines
1.6 KiB
JavaScript
Vendored
const VueRouter = require('vue-router');
|
|
|
|
import Home from './views/Home.vue';
|
|
import Blog from './views/Blog.vue';
|
|
import BlogArticle from './views/BlogArticle.vue';
|
|
import Snippets from './views/Snippets.vue';
|
|
import Contact from './views/Contact.vue';
|
|
|
|
import NotFound from './views/NotFound.vue';
|
|
|
|
const routes = [
|
|
{ path: '/', name: 'index', component: Home },
|
|
{ path: '/blog', name: 'blog', component: Blog },
|
|
{ path: '/blog/:year/:month/:day/:id-:slug', name: 'blog-article', component: BlogArticle, props: true },
|
|
{ path: '/snippets', name: 'snippets', component: Snippets },
|
|
{ path: '/contact', name: 'contact', component: Contact },
|
|
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
|
|
];
|
|
|
|
const router = VueRouter.createRouter({
|
|
history: VueRouter.createWebHistory(),
|
|
routes,
|
|
});
|
|
|
|
const classes = {
|
|
'index': ['page-home'],
|
|
};
|
|
|
|
router.afterEach((to, from, failure) => {
|
|
if (!failure) {
|
|
if (!!from && !!from.name) {
|
|
if (Object.keys(classes).includes(from.name.toString())) {
|
|
for (const className of classes[from.name.toString()]) {
|
|
if (document.body.classList.contains(className)) {
|
|
document.body.classList.remove(className);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!!to && !!to.name) {
|
|
if (Object.keys(classes).includes(to.name.toString())) {
|
|
for (const className of classes[to.name.toString()]) {
|
|
document.body.classList.add(className);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
export default router
|