-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
RouteObject with index=true
should not accept children.
#9343
Conversation
|
Hi @GuptaSiddhant, Welcome, and thank you for contributing to React Router! Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once. You may review the CLA and sign it by adding your name to contributors.yml. Once the CLA is signed, the If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run. Thanks! - The Remix team |
Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳 |
index=true
should not accept children.
If accepted, the docs could be updated to reflect the new RouteObject type. |
Can you add some tests to this? |
@@ -584,7 +584,7 @@ export function createRoutesFromChildren( | |||
handle: element.props.handle, | |||
}; | |||
|
|||
if (element.props.children) { | |||
if (element.props.children && !route.index) { |
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.
I think it would be better to use an invariant
here so that the error is identified and surfaced to the user, instead of silently skipping children in a mismatched scenario?
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.
Add the invariant.
A test is added. |
@GuptaSiddhant Do you mind rebasing this and re-pointing to the dev branch since it contains code changes with the invariants? |
- RouteObject type should accept either index or children.
@brophdawg11 Rebased and pointing to "dev" |
Thank you for this PR @GuptaSiddhant! I dug into this a bit more and this idea can actually be extended both upwards and downwards to get the same type safety inside To make sure we don't lose your contribution I cherry-picked your commits into a new PR (so you retain authorship) and added the additional typing changes on top of them, and we'll get this work merged via that PR. Here's the new PR: #9366 |
RouteObject type should accept either index or children but not both, since an index route cannot has children.