File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
packages/react-router/lib Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -31,22 +31,24 @@ export function href<Path extends keyof Args>(
3131 . replace ( / \/ * \* ? $ / , "" ) // Ignore trailing / and /*, we'll handle it below
3232 . replace (
3333 / \/ : ( [ \w - ] + ) ( \? ) ? / g, // same regex as in .\router\utils.ts: compilePath().
34- ( _ : string , param : string , isOptional ) => {
34+ ( _ : string , param : string , questionMark : string | undefined ) => {
35+ const isRequired = questionMark === undefined ;
3536 const value = params ? params [ param ] : undefined ;
36- if ( isOptional == null && value == null ) {
37+ if ( isRequired && value === undefined ) {
3738 throw new Error (
3839 `Path '${ path } ' requires param '${ param } ' but it was not provided` ,
3940 ) ;
4041 }
41- return value == null ? "" : "/" + value ;
42+ return value === undefined ? "" : "/" + value ;
4243 } ,
4344 ) ;
4445
4546 if ( path . endsWith ( "*" ) ) {
4647 // treat trailing splat the same way as compilePath, and force it to be as if it were `/*`.
4748 // `react-router typegen` will not generate the params for a malformed splat, causing a type error, but we can still do the correct thing here.
48- if ( params && params [ "*" ] != null ) {
49- result += "/" + params [ "*" ] ;
49+ const value = params ? params [ "*" ] : undefined ;
50+ if ( value !== undefined ) {
51+ result += "/" + value ;
5052 }
5153 }
5254
You can’t perform that action at this time.
0 commit comments