126 lines
3.6 KiB
JavaScript
126 lines
3.6 KiB
JavaScript
import { createRouter, createWebHistory } from 'vue-router';
|
|
|
|
import moduleRoutes from './module.routes';
|
|
import portfolioRoutes from './portfolio.routes';
|
|
import onboardingRoutes from './onboarding.routes';
|
|
import meRoutes from './me.routes';
|
|
import authRoutes from './auth.routes';
|
|
import roomRoutes from './room.routes';
|
|
|
|
import { store } from '@/store';
|
|
import { LAYOUT_SIMPLE } from '@/router/core.constants';
|
|
import { EMAIL_NOT_VERIFIED_STATE, NO_VALID_LICENSE_STATE, SUCCESS_STATE } from './oauth.names';
|
|
|
|
import start from '@/pages/start';
|
|
|
|
const instrument = () => import(/* webpackChunkName: "instruments" */ '@/pages/instrument');
|
|
const instrumentOverview = () => import(/* webpackChunkName: "instruments" */ '@/pages/instrumentOverview');
|
|
|
|
const article = () => import(/* webpackChunkName: "news" */ '@/pages/article');
|
|
const news = () => import(/* webpackChunkName: "news" */ '@/pages/news');
|
|
|
|
const surveyPage = () => import(/* webpackChunkName: "survey" */ '@/pages/survey');
|
|
|
|
const styleGuidePage = () => import('@/pages/styleguide');
|
|
const joinClass = () => import('@/pages/joinClass');
|
|
|
|
const topic = () => import('@/pages/topic-page');
|
|
|
|
const p404 = () => import('@/pages/p404');
|
|
const submission = () => import('@/pages/studentSubmission');
|
|
|
|
const postLoginRedirectUrlKey = 'postLoginRedirectionUrl';
|
|
|
|
const notFoundRoute = {
|
|
component: p404,
|
|
meta: {
|
|
layout: 'blank',
|
|
},
|
|
};
|
|
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
name: 'home',
|
|
component: start,
|
|
},
|
|
...moduleRoutes,
|
|
...authRoutes,
|
|
...roomRoutes,
|
|
...onboardingRoutes,
|
|
...portfolioRoutes,
|
|
...meRoutes,
|
|
{ path: '/article/:slug', name: 'article', component: article, meta: { layout: LAYOUT_SIMPLE } },
|
|
{
|
|
path: '/instruments/',
|
|
name: 'instrument-overview',
|
|
component: instrumentOverview,
|
|
},
|
|
{ path: '/instrument/:slug', name: 'instrument', component: instrument, meta: { layout: LAYOUT_SIMPLE } },
|
|
{ path: '/submission/:id', name: 'submission', component: submission, meta: { layout: LAYOUT_SIMPLE } },
|
|
{ path: '/topic/:topicSlug', name: 'topic', component: topic, alias: '/book/topic/:topicSlug' },
|
|
{ path: '/join-class', name: 'join-class', component: joinClass, meta: { layout: LAYOUT_SIMPLE } },
|
|
{
|
|
path: '/survey/:id',
|
|
component: surveyPage,
|
|
name: 'survey',
|
|
props: true,
|
|
meta: { layout: LAYOUT_SIMPLE },
|
|
},
|
|
{
|
|
path: '/news',
|
|
component: news,
|
|
name: 'news',
|
|
},
|
|
{
|
|
path: '/oauth-redirect',
|
|
redirect: (to) => {
|
|
switch (to.query.state) {
|
|
case EMAIL_NOT_VERIFIED_STATE:
|
|
return '/verify-email';
|
|
case NO_VALID_LICENSE_STATE:
|
|
return '/license-activation';
|
|
case SUCCESS_STATE:
|
|
if (window.localStorage && localStorage.getItem(postLoginRedirectUrlKey)) {
|
|
const redirectUrl = localStorage.getItem(postLoginRedirectUrlKey);
|
|
localStorage.removeItem(postLoginRedirectUrlKey);
|
|
return redirectUrl;
|
|
}
|
|
return '/';
|
|
default:
|
|
return '/unknown-auth-error';
|
|
}
|
|
},
|
|
},
|
|
{ path: '/styleguide', component: styleGuidePage },
|
|
{
|
|
path: '/not-found',
|
|
name: 'not-found',
|
|
...notFoundRoute,
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
...notFoundRoute,
|
|
},
|
|
];
|
|
|
|
|
|
const router = createRouter({
|
|
routes,
|
|
history: createWebHistory(),
|
|
mode: 'history',
|
|
scrollBehavior(to, from, savedPosition) {
|
|
if (savedPosition) {
|
|
return savedPosition;
|
|
}
|
|
return { left: 0, top: 0 };
|
|
},
|
|
});
|
|
|
|
router.afterEach(() => {
|
|
store.commit('setEditModule', false);
|
|
store.dispatch('showMobileNavigation', false);
|
|
});
|
|
|
|
export { router, postLoginRedirectUrlKey };
|