Why react router v6 useParams returns object with properties possibly 'undefined'?
In my code below, my IDE indicates const slug: string | undefined.
const { slug } = useParams<"slug">();
It is because of the Params type definition:
/**
* The parameters that were parsed from the URL path.
*/
export type Params<Key extends string = string> = {
readonly [key in Key]: string | undefined;
};
But why is not Params defined like this (without the | undefined):
export type Params<Key extends string = string> = {
readonly [key in Key]: string;
};
If a route with a parameter matches the URL then the parameter cannot be undefined. So, is there any case when useParams returns with an undefined param?