fix(params): enforce non-undefined route parameter values
- Update `Params` type to disallow `undefined` values for clarity. - Default route parameter values to empty strings if `null` or `undefined`. Signed-off-by: Max P. <Mail@MPassarello.de>
This commit is contained in:
@@ -7,4 +7,4 @@
|
|||||||
* All values are strings and should be considered read-only, as they are
|
* All values are strings and should be considered read-only, as they are
|
||||||
* extracted by the router and should not be modified by application code.
|
* extracted by the router and should not be modified by application code.
|
||||||
*/
|
*/
|
||||||
export type Params = Record<string, string | undefined>;
|
export type Params = Record<string, string>;
|
||||||
|
@@ -35,7 +35,7 @@ export function createRouteMatcher(
|
|||||||
// 3b. Extract route params
|
// 3b. Extract route params
|
||||||
const params: Params = {};
|
const params: Params = {};
|
||||||
for (const [key, value] of Object.entries(result.pathname.groups)) {
|
for (const [key, value] of Object.entries(result.pathname.groups)) {
|
||||||
params[key] = value;
|
params[key] = value ?? ''; // null → empty string
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3c. Extract query parameters – keep duplicates as arrays
|
// 3c. Extract query parameters – keep duplicates as arrays
|
||||||
|
Reference in New Issue
Block a user