-
-
Save abodacs/53debbe7f87182f77c830d31ba79a25b to your computer and use it in GitHub Desktop.
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
const routes = { | |
home: '/', | |
transactions: '/transactions', | |
transactionDetails: '/transactions/:uuid', | |
} | |
const urls: Record< | |
keyof typeof routes, | |
{ get: (params?: any) => string; route: string } | |
> = new Proxy(routes, { | |
get(target: any, propKey: any) { | |
const route = target[propKey] | |
return { | |
get: (params: Record<string, string>, query?: Record<string, string>) => | |
generatePath(route, params) + | |
(query ? `?${new URLSearchParams(query).toString()}` : ''), | |
route, | |
} | |
}, | |
}) | |
// <Route exact path={urls.home.route}> | |
// <HomePage /> | |
// </Route> | |
// <Link href={urls.transactionDetails.get({ uuid: 123 } )} /> // /transactions/123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
remix-run/react-router#9826