Skip to content
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

Merged

Conversation

kellyrmilligan
Copy link
Contributor

I thought this might help clarify the parameters of matchRoutes.

@@ -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
Copy link
Contributor

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'))

```

Copy link
Contributor

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).

@kellyrmilligan
Copy link
Contributor Author

@pshrmn good point. is the link I added instead any good? I tried to do both 😄

@kellyrmilligan
Copy link
Contributor Author

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

@pshrmn
Copy link
Contributor

pshrmn commented May 3, 2017

history does the decoding in parsePath, but I think that is going to be moved to createLocation. There is an issue with history right now because when I added automatic decoding, I also added automatic encoding. Unfortunately, that results in double encoding if someone pre-encodes their pathname. You can check remix-run/history/pull/465 for more information

I'm not actually particularly sure how react-router-config would work on the server because I don't use the package. You are creating a memory history at some point, right? I would use the location object generated by that.

const history = createMemoryHistory({ initialEntries: [request.path] })
const { pathname } = history.location
const branch = matchRoutes(routes, pathname)

@kellyrmilligan
Copy link
Contributor Author

@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.

@pshrmn
Copy link
Contributor

pshrmn commented May 4, 2017

The <StaticRouter> module includes its own createLocation function that calls parsePath (which currently decodes). There will probably end up being an issue with that if/when decodeURI gets moved to createLocation.

@kellyrmilligan
Copy link
Contributor Author

I just went with decodeUri in the module due to the flow of the rendering/data fetching I'm doing

@timdorr timdorr merged commit 819b6ac into remix-run:master Oct 3, 2017
@timdorr
Copy link
Member

timdorr commented Oct 3, 2017

Not sure how this got missed, since it's easy peasy.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants