Created
October 2, 2020 22:08
-
-
Save createdbymahmood/de6247d02cb01de1b3af0e8ba892544e to your computer and use it in GitHub Desktop.
react-router routeTo path generator helper π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { generatePath } from "react-router-dom"; | |
import { stringify } from "qs"; | |
import get from "lodash/get"; | |
import __ROUTES__ from "constants/routes"; | |
type PathType = keyof typeof __ROUTES__; | |
type ParamsType = { [paramName: string]: string | number | boolean }; | |
export const routeTo = ( | |
path: PathType, | |
params?: ParamsType, | |
queryString?: object | |
) => { | |
const url = generatePath(get(__ROUTES__, path), params); | |
return queryString ? `${url}?${stringify(queryString)}` : url; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment