You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mvfront-react/services/routes.ts

36 lines
825 B

/**
* This file provides the paths to the pages
*/
import { NextRouter } from 'next/router';
import { getWindowUrl, displayRef, getLocaleShort } from './utils';
export enum RouteTypes {
HOME = '',
CREATE_ELECTION = 'admin/new',
ADMIN = 'admin',
BALLOT = 'ballot',
ENDED_VOTE = 'end',
VOTE = 'vote',
RESULTS = 'result',
}
export const getUrl = (
type: RouteTypes,
router: NextRouter,
ref?: string,
token?: string
): URL => {
const locale = getLocaleShort(router);
if (ref) {
if (token) {
const path = `/${locale}/${type}/${displayRef(ref)}/${token}`;
return new URL(path, getWindowUrl());
}
const path = `/${locale}/${type}/${displayRef(ref)}`;
return new URL(path, getWindowUrl());
}
const path = `/${locale}/${type}`;
return new URL(path, getWindowUrl());
};