mirror of
https://github.com/IT4Change/ohmyform-ui.git
synced 2025-12-13 09:45:50 +00:00
20 lines
484 B
TypeScript
20 lines
484 B
TypeScript
import React from 'react';
|
|
import {useRouter as useNextRouter} from 'next/router';
|
|
|
|
|
|
function parseQuery(path) {
|
|
const query = {};
|
|
const regex = /[?&]([^&$=]+)(=([^&$]+))?/g;
|
|
let param;
|
|
while ((param = regex.exec(path)) !== null) {
|
|
query[decodeURIComponent(param[1])] = decodeURIComponent(param[3]);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
export function useRouter() {
|
|
const router = useNextRouter();
|
|
router.query = {...router.query, ...parseQuery(router.asPath)};
|
|
return router;
|
|
}
|