-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameter values are encoded (react-router v6) #7173
Comments
The params are specifically not decoded right now. We still have that as an open question about how to handle it. This has been an ongoing issue with the history library: remix-run/history#745 and remix-run/history#505 The plan there in 5.0 is just to not touch them at all. Let downstream libraries and users handle it if they want. I think we'll take the same approach here, so it will be up to you to decode those values further. It's a similar philosophy to our query string handling (which we also don't parse). |
Maybe as the API is hooks based now maybe adding a parameter to useParams to either force raw values or force decoding could be added? I feel that the principle of least surprise should apply here. |
I wonder what is actually least surprising. I think I'd want the raw param. If I wanted the decoded params I could easily create a |
+1 for the raw params, while it would be helpful to also offer a shortcut to retrieve the decoded version. As a question during parsing parameters, to decode or not may seem subtle, but when it comes to whether to encode parameters with I guess it's good to keep path generation and parsing logic consistent, so it's best for |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Hey, I actually would like to have a raw parameter, and useParams returns decoded already. path: /companies/Samsung%2CInc,Lenovo%2CInc
Any recommendations here? |
Unfortunately you're going to have to parse it yourself. const location = useLocation()
const companies = location.pathname.match(/^\/companies\/(.*)$/)![1];
console.log(companies.split(",").map((c) => decodeURIComponent(c))); |
Oh man, this not good, I think there should be a hook to get the RAW params. |
True, but a library isn't going to cover everyone's needs. The fact that it's OSS means you can submit a PR, or at the very least, write your own code to handle your particular usecase. |
Version
react-router-dom@6.0.0-alpha.2
Test Case
https://codesandbox.io/s/react-router-tv3xb
Steps to reproduce
Use the test case and click on the parameter test links
Expected Behavior
The param values should not have % encoded characters.
Actual Behavior
The param values have encoded characters.
The text was updated successfully, but these errors were encountered: