keycloak-scim/js/apps/admin-ui/src/utils/generateEncodedPath.ts

18 lines
504 B
TypeScript
Raw Normal View History

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);
}