-
-
Save ymulenll/121a2933f4cd32247fd6d7c272079770 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