Basic router cleanup

This commit is contained in:
Karl Carriere
2024-12-17 11:05:19 -05:00
parent ccc0bef233
commit 7adc701594

View File

@@ -1,58 +1,61 @@
import {createRouter, createWebHistory} from 'vue-router' import { useAuthStore } from '@/stores/authStore.js';
import About from '@/views/documentation/About.vue' import CTA01 from '@/views/CTA01.vue';
import ContentPolicy from '@/views/documentation/ContentPolicy.vue' import CreatorList from '@/views/browser/CreatorList.vue';
import FAQ from '@/views/documentation/FAQ.vue' import ContentEditorPage from '@/views/contents/ContentEditorPage.vue';
import Pricing from '@/views/documentation/Pricing.vue' import ContentPage from '@/views/contents/ContentPage.vue';
import CreatorGuide from '@/views/documentation/CreatorGuide.vue' import PostContent from '@/views/contents/PostContent.vue';
import HelpAndContact from '@/views/documentation/HelpAndContact.vue' import CreatorContent from '@/views/creators/CreatorContent.vue';
import TermsAndConditions from '@/views/documentation/TermsAndConditions.vue' import CreatorHome from '@/views/creators/CreatorHome.vue';
import LoginView from '../views/LoginView.vue' import CreatorLayout from '@/views/creators/CreatorLayout.vue';
import PaymentCompleted from '../views/PayementCompleted.vue' import ExclusiveContentCard from '@/views/creators/ExclusiveContentCard.vue';
import Home from '../views/main/Home.vue' import SubscriptionMenu from '@/views/creators/SubscriptionMenu.vue';
import Wallet from '../views/main/Wallet.vue' import About from '@/views/documentation/About.vue';
import ProfilePage from '@/views/profile/ProfilePage.vue' import ContentPolicy from '@/views/documentation/ContentPolicy.vue';
import CreatorList from '@/views/browser/CreatorList.vue' import CreatorGuide from '@/views/documentation/CreatorGuide.vue';
import PostContent from "@/views/contents/PostContent.vue"; import DocumentationHome from '@/views/documentation/DocumentationHome.vue';
import ContentEditorPage from "@/views/contents/ContentEditorPage.vue"; import DocumentationLayout from '@/views/documentation/DocumentationLayout.vue';
import {useAuthStore} from "@/stores/authStore.js"; import FAQ from '@/views/documentation/FAQ.vue';
import CreatorLayout from "@/views/creators/CreatorLayout.vue"; import HelpAndContact from '@/views/documentation/HelpAndContact.vue';
import ContentPage from "@/views/contents/ContentPage.vue"; import Pricing from '@/views/documentation/Pricing.vue';
import CreatorContent from "@/views/creators/CreatorContent.vue"; import TermsAndConditions from '@/views/documentation/TermsAndConditions.vue';
import CreatorHome from "@/views/creators/CreatorHome.vue"; import ProfilePage from '@/views/profile/ProfilePage.vue';
import CTA01 from "@/views/CTA01.vue"; import { createRouter, createWebHistory } from 'vue-router';
import SubscriptionMenu from "@/views/creators/SubscriptionMenu.vue"; import LoginView from '../views/LoginView.vue';
import DocumentationLayout from "@/views/documentation/DocumentationLayout.vue"; import PaymentCompleted from '../views/PayementCompleted.vue';
import ExclusiveContentCard from "@/views/creators/ExclusiveContentCard.vue"; import Home from '../views/main/Home.vue';
import DocumentationHome from "@/views/documentation/DocumentationHome.vue"; import Wallet from '../views/main/Wallet.vue';
const routes = [ const routes = [
{ {
path: '/cta01', path: '/cta01',
component: CTA01 component: CTA01,
}, },
{ {
path: '/landing', path: '/landing',
component: Home name: 'landing',
component: Home,
}, },
{ {
path: '/', path: '/',
redirect: '/@hutopy', redirect: { name: 'landing' },
}, },
{ {
path: '/browse', path: '/browse',
component: CreatorList component: CreatorList,
redirect: { name: 'landing' }, // TODO remove this line when the page is ready
}, },
{ {
path: '/content/editor', path: '/content/editor',
component: ContentEditorPage component: ContentEditorPage,
}, },
{ {
path: '/content/:contentId', path: '/content/:contentId',
component: ContentPage component: ContentPage,
}, },
{ {
path: '/@:creator', path: '/@:creator',
component: CreatorLayout, component: CreatorLayout,
name: 'creator',
children: [ children: [
{ {
path: '', path: '',
@@ -60,17 +63,18 @@ const routes = [
}, },
{ {
path: 'content', path: 'content',
component: CreatorContent component: CreatorContent,
}, },
{ {
path: 'subscription', path: 'subscription',
component: SubscriptionMenu component: SubscriptionMenu,
redirect: { name: 'creator' }, // TODO remove this line when the page is ready
}, },
{ {
path: 'exclusivecontentcard', path: 'exclusivecontentcard',
component: ExclusiveContentCard component: ExclusiveContentCard,
}, },
] ],
}, },
{ {
path: '/documents', path: '/documents',
@@ -79,90 +83,91 @@ const routes = [
{ {
path: '', path: '',
component: DocumentationHome, component: DocumentationHome,
redirect: { name: 'about' }, // TODO remove this line when the page is ready
}, },
{ {
path: 'helpandcontact', path: 'helpandcontact',
component: HelpAndContact name: 'helpandcontact',
component: HelpAndContact,
}, },
{ {
path: 'termsandconditions', path: 'termsandconditions',
name: 'termsandconditions', name: 'termsandconditions',
component: TermsAndConditions component: TermsAndConditions,
}, },
{ {
path: 'contentpolicy', path: 'contentpolicy',
name: 'contentpolicy', name: 'contentpolicy',
component: ContentPolicy component: ContentPolicy,
}, },
{ {
path: 'faq', path: 'faq',
name: 'FAQ', name: 'FAQ',
component: FAQ component: FAQ,
}, },
{ {
path: 'guideforcreators', path: 'guideforcreators',
name: 'guideforcreators', name: 'guideforcreators',
component: CreatorGuide component: CreatorGuide,
}, },
{ {
path: 'about', path: 'about',
name: 'about', name: 'about',
component: About component: About,
}, },
{ {
path: 'pricing', path: 'pricing',
name: 'pricing', name: 'pricing',
component: Pricing component: Pricing,
}, },
] ],
}, },
{ {
path: '/content/post', path: '/content/post',
component: PostContent, component: PostContent,
redirect: { name: 'landing' }, // TODO remove this line when the page is ready
}, },
{ {
path: '/login', path: '/login',
name: 'login', name: 'login',
component: LoginView component: LoginView,
meta: { notAuthenticated: true },
}, },
{ {
path: '/paymentcompleted', path: '/paymentcompleted',
name: 'PaymentCompleted', name: 'PaymentCompleted',
component: PaymentCompleted, component: PaymentCompleted,
meta: {requiresAuth: true} meta: { requiresAuth: true },
}, },
{ {
path: '/wallet', path: '/wallet',
name: 'wallet', name: 'wallet',
component: Wallet, component: Wallet,
meta: {requiresAuth: true} meta: { requiresAuth: true },
}, },
{ {
path: '/profile', path: '/profile',
name: 'profile', name: 'profile',
component: ProfilePage, component: ProfilePage,
meta: {requiresAuth: true} meta: { requiresAuth: true },
} },
] ];
const router = createRouter({ const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL), history: createWebHistory(import.meta.env.BASE_URL),
routes routes,
}) });
// Navigation guards // Navigation guards
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
const authStore = useAuthStore(); const authStore = useAuthStore();
if (to.matched.some(record => record.meta.requiresAuth)) { if (to.matched.some((record) => record.meta.requiresAuth)) {
if (!authStore.isAuthenticated) { if (!authStore.isAuthenticated) next({ name: 'login' });
next('/'); } else if (to.matched.some((record) => record.meta.notAuthenticated)) {
} else { if (authStore.isAuthenticated) next({ name: 'landing' });
next();
} }
} else {
next(); next();
} });
})
export default router; export default router;