Skip to content

Changed behaviour for optional params #1893

Open
@bodograumann

Description

Reproduction

https://github.com/vuejs/router/blob/main/packages/router/__tests__/router.spec.ts#L300-L328

Steps to reproduce the bug

  • Route with an optional parameter
  • Set the parameter
  • Unset the parameter with undefined

Expected behavior

I would have expected the parameter to be unset as in versions before 4.2, but I know this might not have been the intended behaviour.

Actual behavior

This issue is about the changes in #1814

It is a bit of a mess, because several things come together.

  1. The documentation says undefined and null are stringified: 0c91292
  2. Before the change they where not stringified, but could actually be used to unset optional params in the current route.
  3. After the change they are actually removed instead of stringified.

Additional information

Whatever the original intented use was, the use-case of unsetting the value of an optional parameter was never properly documented.
In practice using undefined worked and was used by us and others, so the change is causing breakages in real-world usages.

I checked and unsetting an optional parameter with "" did work at least in 4.1.6, but I am not sure if it also did in earlier versions, when we first implemented this code.

Imho using the empty string as "not set" is bad practice and they should be normalized to undefined instead.

Metadata

Assignees

Labels

bugSomething isn't workinghas workaroundA workaround has been found to deal with the issue

Type

No type

Projects

  • Status

    📆 Planned

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions