96 lines
2.2 KiB
TypeScript
96 lines
2.2 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
import { useSessionStore } from "@/stores/sessionStore";
|
|
import AboutView from '../views/AboutView.vue'
|
|
import HomeView from '../views/HomeView.vue'
|
|
import LoginView from '../views/LoginView.vue'
|
|
import ProfileView from '../views/ProfileView.vue'
|
|
import StickerBuilderView from '../views/StickerBuilderView.vue'
|
|
import StickerView from '../views/StickerView.vue'
|
|
import WelcomeView from '../views/WelcomeView.vue'
|
|
|
|
|
|
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})'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
routes: [
|
|
{
|
|
component: AboutView,
|
|
meta: {
|
|
title: 'About',
|
|
},
|
|
name: 'about',
|
|
path: '/about',
|
|
},
|
|
{
|
|
component: HomeView,
|
|
meta: {
|
|
title: 'Home',
|
|
},
|
|
name: 'home',
|
|
path: '/',
|
|
},
|
|
{
|
|
component: ProfileView,
|
|
meta: {
|
|
title: 'Profile',
|
|
},
|
|
name: 'profile',
|
|
path: '/profile/:username?',
|
|
},
|
|
{
|
|
component: StickerBuilderView,
|
|
meta: {
|
|
title: 'Sticker Builder',
|
|
},
|
|
name: 'stickerbuilder',
|
|
path: `/stickerbuilder/${id}`,
|
|
// TODO: Consider using /:id/edit
|
|
},
|
|
{
|
|
component: StickerView,
|
|
meta: {
|
|
title: 'Sticker',
|
|
},
|
|
name: 'sticker',
|
|
path: `/${id}`,
|
|
},
|
|
{
|
|
component: LoginView,
|
|
meta: {
|
|
title: 'Login',
|
|
},
|
|
name: 'login',
|
|
path: '/login',
|
|
},
|
|
{
|
|
component: WelcomeView,
|
|
meta: {
|
|
title: 'Welcome',
|
|
},
|
|
name: 'welcome',
|
|
path: '/welcome',
|
|
},
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to, _from) => {
|
|
const sessionStore= useSessionStore();
|
|
if (sessionStore.isAnonymous && to.name == 'home') {
|
|
return {name: 'welcome'};
|
|
} else if (!sessionStore.isAnonymous && to.name == 'welcome') {
|
|
return {name: 'home'};
|
|
} else if (to.name == 'profile' && to.params.username == "") {
|
|
if (sessionStore.isAnonymous) {
|
|
return {name: 'home'};
|
|
} else {
|
|
// Send to "my" profile page.
|
|
return {name: 'profile', params: {
|
|
username: sessionStore.user.username,
|
|
}};
|
|
}
|
|
}
|
|
});
|
|
|
|
export default router
|