common/Routing: allow RouteParams to be undefined and ignore them in this case

This commit is contained in:
Alice Gaudon 2021-11-24 18:18:55 +01:00
parent 4c895229ec
commit 2b85bea9dd
1 changed files with 5 additions and 2 deletions

View File

@ -1,4 +1,4 @@
export type RouteParams = { [p: string]: string | number } | string[] | string | number;
export type RouteParams = { [p: string]: string | number | undefined } | string[] | string | number;
export type QueryParamsRecord = Record<string, string | number | boolean | null | undefined>;
export type QueryParams = string[][] | QueryParamsRecord | string | URLSearchParams;
@ -43,7 +43,10 @@ export function route(
path = path.replace(/\/+/g, '/');
} else {
for (const key of Object.keys(params)) {
path = path.replace(getRouteParamRegExp(key), params[key].toString());
const paramValue = params[key];
if (paramValue) {
path = path.replace(getRouteParamRegExp(key), paramValue.toString());
}
}
}