import { router } from '../router' import { Location, RawLocation, Route, VueRouter } from 'vue-router/types/router'; export const ROUTES = { // Static routes PAGE_OVERVIEW: 'page-overview', PAGE_CREATE: 'page-create', PAGE_CREATE_IN: 'page-create-in', PAGE_COPY: 'page-copy', PAGE_EDITOR_VERSION: 'page-editor-version', PAGE_EDITOR_EMPTY_TRANSLATION: 'page-editor-empty-translation', PAGE_EDITOR: 'page-editor', ASSET_OVERVIEW: 'asset-overview', ASSET_CREATE: 'asset-create', ASSET_EDIT: 'asset-edit', LANGUAGE_PAGE_TRANSLATIONS: 'language-page-translations', DOCS_OVERVIEW: 'docs-overview', // Dynamic crud routes CRUD_INDEX: (module: string) => `index-${module}`, CRUD_CREATE: (module: string) => `create-${module}`, CRUD_COPY: (module: string) => `copy-${module}`, CRUD_EDITOR: (module: string) => `${module}-editor`, CRUD_EMPTY_TRANSLATION: (module: string) => `empty-translation-${module}`, }; export const SYSTEM_NAVIGATION_ITEMS = { LANGUAGE_PAGE_TRANSLATION_ITEM: { label: 'Vertalingen', href: '/language', icon: 'translate-icon' } } export default class RouteUtils { public static parseEnumFromQuery(value: string | (string | null)[]): T | null { if (value && typeof value === 'string' && typeof parseInt(value) === 'number') { return parseInt(value) as unknown as T; } return null; } public static async persistToQuery(router: VueRouter, route: Route, params: { [key: string]: string | undefined }): Promise { await router.replace({ path: route.path, query: { ...route.query, ...params } }).catch(() => { // fail silently }); } public static async push(location: RawLocation) { await router.push(location).catch(() => { // Uncaught route errors are ignored because they are expected due to route guards redirects }); } public static async replace(location: RawLocation) { await router.replace(location).catch(() => { // Uncaught route errors are ignored because they are expected due to route guards redirects }); } } export const createRoute = (name: string, params?: { [key: string]: string } | null, options?: Omit): RawLocation => { return ({ name, ...(params && { params }), ...options }); }