diff --git a/CHANGELOG.md b/CHANGELOG.md index 631a884..db460da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - do not show login note if it is not set - typo in dropdown options https://github.com/ohmyform/ohmyform/issues/96 - query parms are not parsed https://github.com/ohmyform/ui/pull/27 https://github.com/ohmyform/ohmyform/issues/100 +- errors because of missing user reference (https://github.com/ohmyform/ohmyform/issues/102) ### Security diff --git a/components/use.router.ts b/components/use.router.ts index 18beb4e..c8efed5 100644 --- a/components/use.router.ts +++ b/components/use.router.ts @@ -1,19 +1,19 @@ -import React from 'react'; -import {useRouter as useNextRouter} from 'next/router'; +import { NextRouter, useRouter as useNextRouter } from 'next/router' +const parseQuery = (path) => { + const query = {} + const regex = /[?&]([^&$=]+)(=([^&$]+))?/g + let param: RegExpExecArray -function parseQuery(path) { - const query = {}; - const regex = /[?&]([^&$=]+)(=([^&$]+))?/g; - let param; while ((param = regex.exec(path)) !== null) { - query[decodeURIComponent(param[1])] = decodeURIComponent(param[3]); + query[decodeURIComponent(param[1])] = decodeURIComponent(param[3]) } - return query; + + return query } -export function useRouter() { - const router = useNextRouter(); - router.query = {...router.query, ...parseQuery(router.asPath)}; - return router; +export const useRouter = (): NextRouter => { + const router = useNextRouter() + router.query = { ...router.query, ...parseQuery(router.asPath) } + return router }