schon/storefront/src/router/index.js
Alexandr SaVBaD Waltz 9e837ba568 Features: 1) Implement composables for posts, products, categories, languages, and user deposits with lazy loading and GraphQL integration; 2) Add standalone pages for blog, product, store, and profile with scoped SCSS styling; 3) Add reusable UI components including header, footer, input, button, and textarea; 4) Introduce forms for contact and deposit functionality with validation and localization support; 5) Create GraphQL fragments for users, products, categories, company, orders, languages, and wishlist for efficient data fetching;
Fixes: 1) Correct missing semicolons in Pinia store definitions for cart, company, wishlist, and auth stores; 2) Refactor GraphQL queries to include fragments for improved modularity and readability; 3) Correct error handling in composables like `usePosts` and `useLanguages`;

Extra: Enhanced App.vue to include dynamic company info and language fetching on mount; Added scoped styles for new components and pages.
2025-05-28 15:35:42 +03:00

151 lines
No EOL
3.4 KiB
JavaScript

import {createRouter, createWebHistory, RouterView} from 'vue-router'
import HomePage from "@/pages/home-page.vue";
import translation from "@/core/helpers/translations.js";
import {APP_NAME} from "@/config/index.js";
import NewPasswordForm from "@/components/forms/new-password-form.vue";
import BlogPage from "@/pages/blog-page.vue";
import PostPage from "@/pages/post-page.vue";
import ProfilePage from "@/pages/profile-page.vue";
import {useAuthStore} from "@/stores/auth.js";
import RegisterForm from "@/components/forms/register-form.vue";
import LoginForm from "@/components/forms/login-form.vue";
import ResetPasswordForm from "@/components/forms/reset-password-form.vue";
import StorePage from "@/pages/store-page.vue";
import ProductPage from "@/pages/product-page.vue";
const routes = [
{
path: '/:locale?',
component: RouterView,
beforeEnter: translation.routeMiddleware,
children: [
{
path: '',
name: 'home',
component: HomePage,
meta: {
title: "Home"
}
},
{
path: 'activate-user',
name: 'activate-user',
component: HomePage,
meta: {
title: 'Home'
}
},
{
path: 'reset-password',
name: 'reset-password',
component: NewPasswordForm,
meta: {
title: 'New Password'
}
},
{
path: 'register',
name: 'register',
component: RegisterForm,
meta: {
title: 'Register',
requiresGuest: true
}
},
{
path: 'login',
name: 'login',
component: LoginForm,
meta: {
title: 'Login',
requiresGuest: true
}
},
{
path: 'forgot-password',
name: 'forgot-password',
component: ResetPasswordForm,
meta: {
title: 'Forgot Password',
requiresGuest: true
}
},
{
path: 'blog',
name: 'blog',
component: BlogPage,
meta: {
title: 'Blog'
}
},
{
path: 'blog/post/:postSlug',
name: 'blog-post',
component: PostPage,
meta: {
title: 'Post'
}
},
{
path: 'store',
name: 'store',
component: StorePage,
meta: {
title: 'Store'
}
},
{
path: 'product/:productSlug',
name: 'product',
component: ProductPage,
meta: {
title: 'Product'
}
},
{
path: 'profile',
name: 'profile',
component: ProfilePage,
meta: {
title: 'Profile',
requiresAuth: true
}
}
]
}
]
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes,
scrollBehavior() {
document.querySelector('#top').scrollIntoView({ behavior: 'smooth' })
return {
top: 0,
left: 0,
behavior: 'smooth'
}
}
})
router.beforeEach((to, from, next) => {
const authStore = useAuthStore();
const isAuthenticated = authStore.accessToken
document.title = to.meta.title ? `${APP_NAME} | ` + to.meta?.title : APP_NAME
if (to.meta.requiresAuth && !isAuthenticated) {
return next({
name: 'home',
query: { redirect: to.fullPath }
});
}
if (to.meta.requiresGuest && isAuthenticated) {
return next({ name: 'home' });
}
next();
})
export default router