-
-
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
update readme to clarify pathname #5066
update readme to clarify pathname #5066
Conversation
@@ -78,6 +78,10 @@ const routes = [ | |||
|
|||
Returns an array of matched routes. | |||
|
|||
#### Parameters | |||
- routes - the route configuration | |||
- pathname - the [pathname](https://nodejs.org/api/url.html#url_urlobject_pathname) component of the url |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strictly speaking, this isn't a Node urlObject.pathname
. The linked document specifies that a urlObject.pathname
is not decoded, but the pathname
provided to matchRoutes
should be decoded. If it was not, then routes would not work with unicode characters. history
automatically decodes the pathname
when creating location objects.
I'm not sure if the best fix would be to change the link or just specify that the pathname
should be decoded, but I think that it is a point worth clarifying.
@@ -244,4 +248,3 @@ ReactDOM.render(( | |||
), document.getElementById('root')) | |||
|
|||
``` | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The blank line at the end is intentional (for git).
@pshrmn good point. is the link I added instead any good? I tried to do both 😄 |
Also, do you happen to know where history does this decoding? I am calling react router config in node with the path from hapi and it's the pathname in node so as you pointed out is not decoded |
I'm not actually particularly sure how const history = createMemoryHistory({ initialEntries: [request.path] })
const { pathname } = history.location
const branch = matchRoutes(routes, pathname) |
@pshrmn i'm using static router per the new rr4 docs recommendation. I can send that path without decoding as you mentioned it auto decodes it right? anyway, here's the repo where i'm upgrading it to use RR4 and react-router-config for backend use: https://github.com/kellyrmilligan/hapi-react-redux/tree/rr4upgrade the readme on this branch needs updating, but the api of the hapi plugin is roughly the same. |
The |
I just went with decodeUri in the module due to the flow of the rendering/data fetching I'm doing |
Not sure how this got missed, since it's easy peasy. |
I thought this might help clarify the parameters of
matchRoutes
.