react-navigation / react-navigation/react-navigation

Path values not decoded properly from URL pathname

Open
#11,506 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug platform:web repro provided
Dominant language
TypeScript
Stars
24.5k
Forks
5.1k
Avg merge
1d 5h
Merged PRs (30d)
18

Description

Current behavior

Consider an app with two screens, Home and Test, and with the following linking options:

{ config: { screens: { Test: { path: 'test/:id' } } } }

In the Home screen there is a button which calls the following code:

navigation.navigate('Test', { id: 'test=' })

This changes the location field of the browser to /test/test%3D and switches to the Test screen. Currently useRoute().params.id correctly returns "test=".

However, doing a refresh in the browser will change the value returned from useRoute().params.id to test%3D.

The problem seems to be that values aren't passed via decodeURIComponent when read from location.pathname, and thus the encoded value %3D shows up instead of the = character.

Expected behavior

I expected useRoute().params.id to return "test=" even after a refresh.

Reproduction

https://github.com/LinusU/react-navigation-percent-encoding-issue

Platform
  • Android
  • iOS
  • Web
  • Windows
  • MacOS
Packages
  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-tab-view
Environment
  • I've removed the packages that I don't use
package version
@react-navigation/native 6.1.7
@react-navigation/native-stack 6.9.13
react-native-safe-area-context 4.6.3
react-native-screens 3.22.1
react-native 0.72.3
expo 49.0.5
node 18.12.1
npm or yarn 8.19.2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the URL pathname parsing used by the linking configuration and reproduce the refresh case in the linked repository. Compare parameters produced by navigation with those restored from the pathname; done means an encoded value such as test%3D yields test= after refresh on web.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.