2024-11-16 11:40:53 -05:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
2024-11-26 19:43:08 -05:00
|
|
|
|
2024-12-01 20:54:21 -05:00
|
|
|
import { useSessionStore } from "@/stores/sessionStore";
|
2024-11-16 15:08:09 -05:00
|
|
|
import AboutView from '../views/AboutView.vue'
|
2024-11-21 19:34:28 -05:00
|
|
|
import HomeView from '../views/HomeView.vue'
|
2024-11-24 20:50:39 -05:00
|
|
|
import LoginView from '../views/LoginView.vue'
|
2024-11-21 19:34:28 -05:00
|
|
|
import ProfileView from '../views/ProfileView.vue'
|
2024-11-24 22:07:09 -05:00
|
|
|
import StickerBuilderView from '../views/StickerBuilderView.vue'
|
2024-11-25 20:06:22 -05:00
|
|
|
import StickerView from '../views/StickerView.vue'
|
2024-11-26 19:43:08 -05:00
|
|
|
import WelcomeView from '../views/WelcomeView.vue'
|
|
|
|
|
|
2024-11-16 11:40:53 -05:00
|
|
|
|
2024-12-08 14:40:46 -05:00
|
|
|
const id: string = ':id([0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12})'
|
2024-12-04 17:09:57 -05:00
|
|
|
|
2024-11-16 11:40:53 -05:00
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
|
|
routes: [
|
2024-11-21 19:34:28 -05:00
|
|
|
{
|
2024-11-26 19:43:08 -05:00
|
|
|
component: AboutView,
|
2024-11-21 19:34:28 -05:00
|
|
|
meta: {
|
2024-11-26 19:43:08 -05:00
|
|
|
title: 'About',
|
2024-11-21 19:34:28 -05:00
|
|
|
},
|
2024-11-26 19:43:08 -05:00
|
|
|
name: 'about',
|
|
|
|
|
path: '/about',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
component: HomeView,
|
|
|
|
|
meta: {
|
|
|
|
|
title: 'Home',
|
|
|
|
|
},
|
|
|
|
|
name: 'home',
|
2024-11-26 16:06:53 -05:00
|
|
|
path: '/',
|
2024-11-21 19:34:28 -05:00
|
|
|
},
|
2024-11-16 11:40:53 -05:00
|
|
|
{
|
2024-11-26 19:43:08 -05:00
|
|
|
component: ProfileView,
|
2024-11-17 22:21:56 -05:00
|
|
|
meta: {
|
2024-11-26 19:43:08 -05:00
|
|
|
title: 'Profile',
|
2024-11-17 22:21:56 -05:00
|
|
|
},
|
2024-11-26 19:43:08 -05:00
|
|
|
name: 'profile',
|
2024-11-26 20:39:13 -05:00
|
|
|
path: '/profile/:username?',
|
2024-11-16 11:40:53 -05:00
|
|
|
},
|
2024-11-16 23:04:02 -05:00
|
|
|
{
|
2024-11-24 22:07:09 -05:00
|
|
|
component: StickerBuilderView,
|
2024-11-17 22:21:56 -05:00
|
|
|
meta: {
|
2024-11-24 22:07:09 -05:00
|
|
|
title: 'Sticker Builder',
|
2024-11-17 22:21:56 -05:00
|
|
|
},
|
2024-11-24 22:07:09 -05:00
|
|
|
name: 'stickerbuilder',
|
2024-12-08 14:40:46 -05:00
|
|
|
path: `/stickerbuilder/${id}`,
|
|
|
|
|
// TODO: Consider using /:id/edit
|
2024-11-16 23:04:02 -05:00
|
|
|
},
|
2024-11-25 20:06:22 -05:00
|
|
|
{
|
|
|
|
|
component: StickerView,
|
|
|
|
|
meta: {
|
|
|
|
|
title: 'Sticker',
|
|
|
|
|
},
|
|
|
|
|
name: 'sticker',
|
2024-12-08 14:40:46 -05:00
|
|
|
path: `/${id}`,
|
2024-11-25 20:06:22 -05:00
|
|
|
},
|
2024-11-24 20:50:39 -05:00
|
|
|
{
|
|
|
|
|
component: LoginView,
|
|
|
|
|
meta: {
|
|
|
|
|
title: 'Login',
|
|
|
|
|
},
|
|
|
|
|
name: 'login',
|
|
|
|
|
path: '/login',
|
|
|
|
|
},
|
2024-11-26 19:43:08 -05:00
|
|
|
{
|
|
|
|
|
component: WelcomeView,
|
|
|
|
|
meta: {
|
|
|
|
|
title: 'Welcome',
|
|
|
|
|
},
|
|
|
|
|
name: 'welcome',
|
|
|
|
|
path: '/welcome',
|
|
|
|
|
},
|
2024-11-16 11:40:53 -05:00
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
2024-12-02 19:35:53 -05:00
|
|
|
router.beforeEach((to, _from) => {
|
2024-12-01 20:54:21 -05:00
|
|
|
const sessionStore= useSessionStore();
|
|
|
|
|
if (sessionStore.isAnonymous && to.name == 'home') {
|
2024-11-26 19:43:08 -05:00
|
|
|
return {name: 'welcome'};
|
2024-12-01 20:54:21 -05:00
|
|
|
} else if (!sessionStore.isAnonymous && to.name == 'welcome') {
|
2024-11-26 19:43:08 -05:00
|
|
|
return {name: 'home'};
|
2024-11-26 20:39:13 -05:00
|
|
|
} else if (to.name == 'profile' && to.params.username == "") {
|
2024-12-01 20:54:21 -05:00
|
|
|
if (sessionStore.isAnonymous) {
|
2024-11-26 20:39:13 -05:00
|
|
|
return {name: 'home'};
|
|
|
|
|
} else {
|
|
|
|
|
// Send to "my" profile page.
|
|
|
|
|
return {name: 'profile', params: {
|
2024-12-01 20:54:21 -05:00
|
|
|
username: sessionStore.user.username,
|
2024-11-26 20:39:13 -05:00
|
|
|
}};
|
|
|
|
|
}
|
2024-11-26 19:43:08 -05:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-16 11:40:53 -05:00
|
|
|
export default router
|