question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not proper props.children value when none of the children routes match within the parent component

See original GitHub issue

Version

4.1.1

Test Case

https://codesandbox.io/s/98m413nxqo

Steps to reproduce

Add a nested route is a component with Switch or multiple Route components within. Now navigate to the nested route but in a such way that none of the children routes will match.

In More details:

Parent Component A which is rendered on route /admin has multiple children routes: /admin/details, /admin/home. If /admin/donotexist is called then Component A will have its props.children resolved to an array of Route React components

Expected Behavior

In case when none of the child routes matched you expect to see props.children to be null.

Actual Behavior

In case when none of the child routes marched it is either Switch component or an array of Route components.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
timdorrcommented, Aug 23, 2017

I’m not sure what you’re doing differently, but that’s not what I see:

image

0reactions
anvkcommented, Aug 28, 2017

So for those who is still looking for a solution to this problem. This is a kinda way I managed to solve this in react-router v4.

So for the old v2 code:

<Route path="customers" component={AdminManageCustomersPage}>
    <Route path=":userId">
        <Route path="details" component={AdminManageCustomersDetail} />
        <Route path="address-books" component={AdminManageCustomersAddressBooks} />
    </Route>
</Route>

I converted into the following code:

const AdminManageCustomerRoutes = ({ match }) =>
  <AdminManageCustomersPage>
    <Switch>
      <Route path={`${match.url}/:userId/details`} component={AdminManageCustomersDetail} />
      <Route path={`${match.url}/:userId/address-books`} component={AdminManageCustomersAddressBooks} />
    </Switch>
  </AdminManageCustomersPage>;

...
<Switch>
  ...
  <Route exact path='/customers' component={AdminManageCustomersPage} />
  <Route path='/customers' component={AdminManageCustomerRoutes} />
  ...
</Switch>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Not proper props.children value when none of the ... - GitHub
Now navigate to the nested route but in a such way that none of the children routes will match. In More details: Parent...
Read more >
reactjs - How to update props of child to child component
I'm curious what the LoggedInUser of the app state is. · Well it is meant to be an object, i missdeclareted the string...
Read more >
React Children And Iteration Methods - Smashing Magazine
We are using the React.Children.toArray method to ensure that the children prop is always an array. If we do not do that, doing...
Read more >
Component interaction - Angular
The parent-child relationship of the components is not established within each component's respective class with the local variable technique. Because the class ...
Read more >
Angular Router: Child Routes, Auxiliary Routes, Master Detail
Learn how to use the Angular Router, avoid common pitfalls, learn Child Routes, Auxiliary Routes, setup a Master Detail Routing Scenario.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found