Skip to content

Regression of #13595 - URLs with optional segments should still be included non-expanded in typed href helper if they are unambiguous (no static optional segments) by the supplied params object #13694

Closed
@tobimori

Description

@tobimori

I'm using React Router as a...

framework

Reproduction

See Expected Behavior for Details

System Info

RR 7.6.1

Used Package Manager

pnpm

Expected Behavior

I'm posting this as a bug report since this working behavior was removed/regressed in a minor release, which breaks a few of our sites.

For example, in a lot of our projects we have multiple optional segments that are dynamic. We then use the href helper everywhere to generate correct URLs, and we always supply the params object from ComponentProps.

For example:

href('/:segment?/xxx', params) // params could either be { } or { segment: 'something' }

In this case, the inclusion of the params in the object is optional - it perfectly suited the case.

Now, with the new syntax, I'd have to implement the type checking by myself, the helper is now basically useless:

if("segment" in params) {
   return href('/:segment/xxx', params) 
} else {
   return href('/xxx', params) 
}

(This would grow large in case you have more optional params, we have like 5 in the largest URL, so this would be quite cumbersome to work around.)

Actual Behavior

There's a type error shown for all links since the working behavior was removed in RR 7.6.1.

Ref: #13595

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions