Skip to content
This repository has been archived by the owner on Dec 2, 2023. It is now read-only.

Commit

Permalink
Fixes #100 - Workaround missing query parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fragsalat authored and wodka committed Jul 14, 2020
1 parent 5d8cbbd commit 2cc49bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/form/field.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
19 changes: 19 additions & 0 deletions components/use.router.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 2cc49bd

Please sign in to comment.