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

Fix pathless route's match when parent is null #5964

Merged
merged 6 commits into from
Feb 22, 2018
Merged

Conversation

timdorr
Copy link
Member

@timdorr timdorr commented Feb 22, 2018

Recreating #4704 under a branch on the main repo.

Original PR post:

This moves the logic for getting the match object for a pathless <Route> matchPath. When automatic path resolving is added, matchPath will need access to the parent match, so we will need to pass that argument to matchPath eventually anyways.

When a parent match is null, a match object with default values is returned by matchPath. This match object should not be relied upon for resolving paths, but it will allow a <Route> that uses the component or render prop to render.

Fixes #4695

pshrmn and others added 6 commits February 22, 2018 11:51
The logic for this has been moved to matchPath. When automatic path resolving is added, matchPath will need access to the parent match, so we will need to pass that argument to matchPath eventually anyways.

When a parent match is null, a match object with default values is returned by matchPath. This match object should not be relied upon for resolving paths, but it will allow a <Route> that uses the component or render prop to render.

Fixes #4695
This is only an issue when you use <Route children>. If you render a pathless <Route> inside of a <Route children>, you must also use <Route children> (instead of <Route render> or <Route component>).

This commit also switches withRouter to using <Route children> instead of <Route render> so that it works when the parent match is null.
@timdorr
Copy link
Member Author

timdorr commented Feb 22, 2018

Since I've got the 👍 from @pshrmn's ownership of the original PR, and I also agree this is sensible to merge in, I'm going to do it.

@timdorr timdorr merged commit 46c4c53 into master Feb 22, 2018
@timdorr timdorr deleted the pshrmn-pathless-patch branch February 22, 2018 17:08
@penx
Copy link
Contributor

penx commented Feb 22, 2018

@timdorr unit tests on #5142 are still relevant, useful and not covered by #5964, can you please reopen #5141 for the tests only and I'll rebase from master

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.

3 participants