13207aabac
Closes #22600 Co-authored-by: Jon Koops <jonkoops@gmail.com>
17 lines
504 B
TypeScript
17 lines
504 B
TypeScript
import { generatePath } from "react-router-dom";
|
|
|
|
export type PathParam = { [key: string]: string };
|
|
|
|
export function generateEncodedPath<Path extends string>(
|
|
originalPath: Path,
|
|
params: PathParam,
|
|
): string {
|
|
const encodedParams: PathParam = {};
|
|
|
|
Object.entries(params).forEach(
|
|
([k, v]) => (encodedParams[k] = encodeURIComponent(v)),
|
|
);
|
|
|
|
//TODO: Fix type once https://github.com/remix-run/react-router/pull/10719 is merged.
|
|
return generatePath(originalPath, encodedParams as any);
|
|
}
|