Refactor router
This commit is contained in:
committed by
Thomas Citharel
parent
d73f738b1b
commit
53cb39350a
48
js/src/router/actor.ts
Normal file
48
js/src/router/actor.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import Profile from '@/views/Account/Profile.vue';
|
||||
import CreateGroup from '@/views/Group/Create.vue';
|
||||
import Group from '@/views/Group/Group.vue';
|
||||
import GroupList from '@/views/Group/GroupList.vue';
|
||||
import Identities from '@/views/Account/Identities.vue';
|
||||
|
||||
export enum ActorRouteName {
|
||||
IDENTITIES = 'Identities',
|
||||
GROUP_LIST = 'GroupList',
|
||||
GROUP = 'Group',
|
||||
CREATE_GROUP = 'CreateGroup',
|
||||
PROFILE = 'Profile',
|
||||
}
|
||||
|
||||
export const actorRoutes = [
|
||||
{
|
||||
path: '/identities',
|
||||
name: ActorRouteName.IDENTITIES,
|
||||
component: Identities,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/groups',
|
||||
name: ActorRouteName.GROUP_LIST,
|
||||
component: GroupList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/groups/create',
|
||||
name: ActorRouteName.CREATE_GROUP,
|
||||
component: CreateGroup,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/~:name',
|
||||
name: ActorRouteName.GROUP,
|
||||
component: Group,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/@:name',
|
||||
name: ActorRouteName.PROFILE,
|
||||
component: Profile,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
];
|
||||
22
js/src/router/category.ts
Normal file
22
js/src/router/category.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import CategoryList from '@/views/Category/List.vue';
|
||||
import CreateCategory from '@/views/Category/Create.vue';
|
||||
|
||||
export enum CategoryRouteName {
|
||||
CATEGORY_LIST = 'CategoryList',
|
||||
CREATE_CATEGORY = 'CreateCategory',
|
||||
}
|
||||
|
||||
export const categoryRoutes = [
|
||||
{
|
||||
path: '/category',
|
||||
name: CategoryRouteName.CATEGORY_LIST,
|
||||
component: CategoryList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/category/create',
|
||||
name: CategoryRouteName.CREATE_CATEGORY,
|
||||
component: CreateCategory,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
];
|
||||
47
js/src/router/event.ts
Normal file
47
js/src/router/event.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import EventList from '@/views/Event/EventList.vue';
|
||||
import Location from '@/views/Location.vue';
|
||||
import CreateEvent from '@/views/Event/Create.vue';
|
||||
import Event from '@/views/Event/Event.vue';
|
||||
|
||||
export enum EventRouteName {
|
||||
EVENT_LIST = 'EventList',
|
||||
CREATE_EVENT = 'CreateEvent',
|
||||
EDIT_EVENT = 'EditEvent',
|
||||
EVENT = 'Event',
|
||||
LOCATION = 'Location',
|
||||
}
|
||||
|
||||
export const eventRoutes = [
|
||||
{
|
||||
path: '/events/list/:location?',
|
||||
name: EventRouteName.EVENT_LIST,
|
||||
component: EventList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/events/create',
|
||||
name: EventRouteName.CREATE_EVENT,
|
||||
component: CreateEvent,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/events/:id/edit',
|
||||
name: EventRouteName.EDIT_EVENT,
|
||||
component: CreateEvent,
|
||||
props: true,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/location/new',
|
||||
name: EventRouteName.LOCATION,
|
||||
component: Location,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/events/:uuid',
|
||||
name: EventRouteName.EVENT,
|
||||
component: Event,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
];
|
||||
@@ -2,111 +2,47 @@ import Vue from 'vue';
|
||||
import Router from 'vue-router';
|
||||
import PageNotFound from '@/views/PageNotFound.vue';
|
||||
import Home from '@/views/Home.vue';
|
||||
import Event from '@/views/Event/Event.vue';
|
||||
import EventList from '@/views/Event/EventList.vue';
|
||||
import Location from '@/views/Location.vue';
|
||||
import CreateEvent from '@/views/Event/Create.vue';
|
||||
import CategoryList from '@/views/Category/List.vue';
|
||||
import CreateCategory from '@/views/Category/Create.vue';
|
||||
import Profile from '@/views/Account/Profile.vue';
|
||||
import CreateGroup from '@/views/Group/Create.vue';
|
||||
import Group from '@/views/Group/Group.vue';
|
||||
import GroupList from '@/views/Group/GroupList.vue';
|
||||
import Identities from '@/views/Account/Identities.vue';
|
||||
import userRoutes from './user';
|
||||
import { UserRouteName, userRoutes } from './user';
|
||||
import { EventRouteName, eventRoutes } from '@/router/event';
|
||||
import { ActorRouteName, actorRoutes } from '@/router/actor';
|
||||
import { CategoryRouteName, categoryRoutes } from '@/router/category';
|
||||
|
||||
Vue.use(Router);
|
||||
|
||||
enum GlobalRouteName {
|
||||
HOME = 'Home',
|
||||
PAGE_NOT_FOUND = 'PageNotFound',
|
||||
}
|
||||
|
||||
// Hack to merge enums
|
||||
// tslint:disable:variable-name
|
||||
export const RouteName = {
|
||||
...GlobalRouteName,
|
||||
...UserRouteName,
|
||||
...EventRouteName,
|
||||
...CategoryRouteName,
|
||||
...ActorRouteName,
|
||||
};
|
||||
|
||||
const router = new Router({
|
||||
mode: 'history',
|
||||
base: '/',
|
||||
routes: [
|
||||
...userRoutes,
|
||||
...eventRoutes,
|
||||
...categoryRoutes,
|
||||
...actorRoutes,
|
||||
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
name: RouteName.HOME,
|
||||
component: Home,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/events/list/:location?',
|
||||
name: 'EventList',
|
||||
component: EventList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/events/create',
|
||||
name: 'CreateEvent',
|
||||
component: CreateEvent,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/events/:id/edit',
|
||||
name: 'EditEvent',
|
||||
component: CreateEvent,
|
||||
props: true,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/location/new',
|
||||
name: 'Location',
|
||||
component: Location,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/category',
|
||||
name: 'CategoryList',
|
||||
component: CategoryList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/category/create',
|
||||
name: 'CreateCategory',
|
||||
component: CreateCategory,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/identities',
|
||||
name: 'Identities',
|
||||
component: Identities,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/groups',
|
||||
name: 'GroupList',
|
||||
component: GroupList,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/groups/create',
|
||||
name: 'CreateGroup',
|
||||
component: CreateGroup,
|
||||
meta: { requiredAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/~:name',
|
||||
name: 'Group',
|
||||
component: Group,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/@:name',
|
||||
name: 'Profile',
|
||||
component: Profile,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/events/:uuid',
|
||||
name: 'Event',
|
||||
component: Event,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
|
||||
{
|
||||
path: '*',
|
||||
name: 'PageNotFound',
|
||||
name: RouteName.PAGE_NOT_FOUND,
|
||||
component: PageNotFound,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
|
||||
@@ -6,53 +6,63 @@ import ResendConfirmation from '@/views/User/ResendConfirmation.vue';
|
||||
import SendPasswordReset from '@/views/User/SendPasswordReset.vue';
|
||||
import PasswordReset from '@/views/User/PasswordReset.vue';
|
||||
|
||||
export default [
|
||||
export enum UserRouteName {
|
||||
REGISTER = 'Register',
|
||||
REGISTER_PROFILE = 'RegisterProfile',
|
||||
RESEND_CONFIRMATION = 'ResendConfirmation',
|
||||
SEND_PASSWORD_RESET = 'SendPasswordReset',
|
||||
PASSWORD_RESET = 'PasswordReset',
|
||||
VALIDATE = 'Validate',
|
||||
LOGIN = 'Login',
|
||||
}
|
||||
|
||||
export const userRoutes = [
|
||||
{
|
||||
path: '/register/user',
|
||||
name: 'Register',
|
||||
name: UserRouteName.REGISTER,
|
||||
component: RegisterUser,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/register/profile',
|
||||
name: 'RegisterProfile',
|
||||
name: UserRouteName.REGISTER_PROFILE,
|
||||
component: RegisterProfile,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/resend-instructions',
|
||||
name: 'ResendConfirmation',
|
||||
name: UserRouteName.RESEND_CONFIRMATION,
|
||||
component: ResendConfirmation,
|
||||
props: true,
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/password-reset/send',
|
||||
name: 'SendPasswordReset',
|
||||
name: UserRouteName.SEND_PASSWORD_RESET,
|
||||
component: SendPasswordReset,
|
||||
props: true,
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/password-reset/:token',
|
||||
name: 'PasswordReset',
|
||||
name: UserRouteName.PASSWORD_RESET,
|
||||
component: PasswordReset,
|
||||
meta: { requiresAuth: false },
|
||||
props: true,
|
||||
},
|
||||
{
|
||||
path: '/validate/:token',
|
||||
name: 'Validate',
|
||||
name: UserRouteName.VALIDATE,
|
||||
component: Validate,
|
||||
// We can only pass string values through params, therefore
|
||||
props: (route) => ({ email: route.params.email, userAlreadyActivated: route.params.userAlreadyActivated === 'true'}),
|
||||
props: (route) => ({ email: route.params.email, userAlreadyActivated: route.params.userAlreadyActivated === 'true' }),
|
||||
meta: { requiresAuth: false },
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
name: UserRouteName.LOGIN,
|
||||
component: Login,
|
||||
props: true,
|
||||
meta: { requiredAuth: false },
|
||||
|
||||
Reference in New Issue
Block a user