Skip to content

fix(dom): decode pathname in NavLink active comparison - #15405

Open
ErfanBagheri404 wants to merge 1 commit into
remix-run:mainfrom
ErfanBagheri404:fix/navlink-special-character-matching
Open

fix(dom): decode pathname in NavLink active comparison#15405
ErfanBagheri404 wants to merge 1 commit into
remix-run:mainfrom
ErfanBagheri404:fix/navlink-special-character-matching

Conversation

@ErfanBagheri404

Copy link
Copy Markdown

Fixes #10781

navigator.encodeLocation percent-encodes special characters (e.g. | ? %7C) via new URL(), but location.pathname from the browser keeps them raw. This caused NavLink to never match when dynamic segments contained characters like |.

Decode both sides with the existing decodePath helper before comparing so the active-state check is encoding-consistent. Added a regression test for the pipe character.

Also related to #14619.

Encode a Location the same way window.location would. The browser's
location.pathname does not encode special characters like pipe (|),
but navigator.encodeLocation (via new URL) percent-encodes them to
%7C. This caused NavLink to always report as inactive when using
these characters in dynamic segments.

Decode both sides with the existing decodePath helper before comparing,
so the comparison works consistently regardless of the encoding path.

Fixes remix-run#10781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: NavLink encodes special characters differently than history

2 participants