mirror of
https://github.com/IT4Change/ohmyform-ui.git
synced 2025-12-13 09:45:50 +00:00
Fixes #100 - Workaround missing query parameters
This commit is contained in:
parent
5d8cbbdf4e
commit
2cc49bdce3
@ -1,11 +1,11 @@
|
||||
import { Form, message } from 'antd'
|
||||
import { useForm } from 'antd/lib/form/Form'
|
||||
import { useRouter } from 'next/router'
|
||||
import React from 'react'
|
||||
import { FormDesignFragment, FormFieldFragment } from '../../graphql/fragment/form.fragment'
|
||||
import { StyledButton } from '../styled/button'
|
||||
import { StyledH1 } from '../styled/h1'
|
||||
import { StyledMarkdown } from '../styled/markdown'
|
||||
import { useRouter } from '../use.router'
|
||||
import { fieldTypes } from './types'
|
||||
import { TextType } from './types/text.type'
|
||||
import { FieldTypeProps } from './types/type.props'
|
||||
|
||||
19
components/use.router.ts
Normal file
19
components/use.router.ts
Normal file
@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user