transform query to key value pair

This commit is contained in:
NikolaBorislavovHristov 2019-06-03 13:47:06 +03:00
parent ed1999d572
commit 706e2082c4

View file

@ -39,7 +39,11 @@ const Router = ({ className, homePath, viewsConfig, onPathNotMatch }) => {
const routeViewIndex = viewsConfig.findIndex((v) => v.includes(routeConfig));
const match = routeConfig.regexp.exec(pathname);
const queryParams = new URLSearchParams(query);
const queryParams = Array.from(new URLSearchParams(query !== null ? query : '').entries())
.reduce((result, [key, value]) => {
result[key] = value;
return result;
}, {});
const urlParams = routeConfig.keys.reduce((urlParams, key, index) => {
if (typeof match[index + 1] === 'string') {
urlParams[key.name] = match[index + 1];