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,168 +1,173 @@
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: '/', {
redirect: '/@hutopy', path: '/',
}, redirect: { name: 'landing' },
{ },
path: '/browse', {
component: CreatorList path: '/browse',
}, component: CreatorList,
{ redirect: { name: 'landing' }, // TODO remove this line when the page is ready
path: '/content/editor', },
component: ContentEditorPage {
}, path: '/content/editor',
{ component: ContentEditorPage,
path: '/content/:contentId', },
component: ContentPage {
}, path: '/content/:contentId',
{ component: ContentPage,
path: '/@:creator', },
component: CreatorLayout, {
children: [ path: '/@:creator',
{ component: CreatorLayout,
path: '', name: 'creator',
component: CreatorHome, children: [
}, {
{ path: '',
path: 'content', component: CreatorHome,
component: CreatorContent },
}, {
{ path: 'content',
path: 'subscription', component: CreatorContent,
component: SubscriptionMenu },
}, {
{ path: 'subscription',
path: 'exclusivecontentcard', component: SubscriptionMenu,
component: ExclusiveContentCard redirect: { name: 'creator' }, // TODO remove this line when the page is ready
}, },
] {
}, path: 'exclusivecontentcard',
{ component: ExclusiveContentCard,
path: '/documents', },
component: DocumentationLayout, ],
children: [ },
{ {
path: '', path: '/documents',
component: DocumentationHome, component: DocumentationLayout,
}, children: [
{ {
path: 'helpandcontact', path: '',
component: HelpAndContact component: DocumentationHome,
}, redirect: { name: 'about' }, // TODO remove this line when the page is ready
{ },
path: 'termsandconditions', {
name: 'termsandconditions', path: 'helpandcontact',
component: TermsAndConditions name: 'helpandcontact',
}, component: HelpAndContact,
{ },
path: 'contentpolicy', {
name: 'contentpolicy', path: 'termsandconditions',
component: ContentPolicy name: 'termsandconditions',
}, component: TermsAndConditions,
{ },
path: 'faq', {
name: 'FAQ', path: 'contentpolicy',
component: FAQ name: 'contentpolicy',
}, component: ContentPolicy,
{ },
path: 'guideforcreators', {
name: 'guideforcreators', path: 'faq',
component: CreatorGuide name: 'FAQ',
}, component: FAQ,
{ },
path: 'about', {
name: 'about', path: 'guideforcreators',
component: About name: 'guideforcreators',
}, component: CreatorGuide,
{ },
path: 'pricing', {
name: 'pricing', path: 'about',
component: Pricing name: 'about',
}, component: About,
] },
}, {
{ path: 'pricing',
path: '/content/post', name: 'pricing',
component: PostContent, component: Pricing,
}, },
{ ],
path: '/login', },
name: 'login', {
component: LoginView path: '/content/post',
}, component: PostContent,
{ redirect: { name: 'landing' }, // TODO remove this line when the page is ready
path: '/paymentcompleted', },
name: 'PaymentCompleted', {
component: PaymentCompleted, path: '/login',
meta: {requiresAuth: true} name: 'login',
}, component: LoginView,
{ meta: { notAuthenticated: true },
path: '/wallet', },
name: 'wallet', {
component: Wallet, path: '/paymentcompleted',
meta: {requiresAuth: true} name: 'PaymentCompleted',
}, component: PaymentCompleted,
{ meta: { requiresAuth: true },
path: '/profile', },
name: 'profile', {
component: ProfilePage, path: '/wallet',
meta: {requiresAuth: true} name: 'wallet',
} component: Wallet,
] meta: { requiresAuth: true },
},
{
path: '/profile',
name: 'profile',
component: ProfilePage,
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(); }
} next();
} else { });
next();
}
})
export default router; export default router;