Skip to content

Warn when Router is given >1 children #4450

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

Merged

Conversation

jackfranklin
Copy link
Contributor

As per issue #4444, this PR adds an invariant which provides a nicer
error message from Router if it is given multiple children.

Any feedback on the approach, etc, is very welcome! I hope it's OK :)

As per issue remix-run#4444, this PR adds an invariant which provides a nicer
error message from `Router` if it is given multiple children.
@@ -21,6 +22,11 @@ class Router extends React.Component {

render() {
const { children } = this.props
invariant(
children == undefined || React.Children.count(children) === 1,
'A <Router> must have at most one child element.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The phrase must have at most sounds odd to me. I think that A <Router> can only have one child element. would be clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I would agree that that could be rephrased. I like yours better. Will see what everyone else thinks but happy to reword.

Copy link
Member

@mjackson mjackson Feb 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say A <Router> may have only one child element

Copy link
Member

@mjackson mjackson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing tests! Let's update the message to A <Router> may have only one child element and we can merge :)

@jackfranklin
Copy link
Contributor Author

@mjackson done! 🎉

@jackfranklin
Copy link
Contributor Author

@mjackson the tests work locally - not sure why they have failed on Travis :/

@pshrmn
Copy link
Contributor

pshrmn commented Feb 5, 2017

@jackfranklin #4470

@mjackson mjackson merged commit d89a87a into remix-run:v4 Feb 5, 2017
@mjackson
Copy link
Member

mjackson commented Feb 5, 2017

Thanks, @jackfranklin! We'll get those Travis tests worked out soon, don't you worry ;)

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

3 participants