reach / router

https://reach.tech/router
MIT License
6.9k stars 326 forks source link

Children of <Router> must have a `path` or `default` prop #352

Open rkingon opened 4 years ago

rkingon commented 4 years ago

I see this has been discussed before, but still seems to be an issue ( #248 )

Here is a codesandbox (nav to either one or two): https://codesandbox.io/s/reach-router-children-bug-pqei6

This sandbox is a very narrow example, in my case I have a real use case for wanting my "Route" to have children and use those children rather than using a prop.

Romcol commented 4 years ago

Hi,

You are right. Actually using prop children doesn't work.

If you pass the children through another props, it works : https://codesandbox.io/s/reach-router-children-bug-uhk64?fontsize=14&hidenavigation=1&theme=dark.

I encountered this problem before, I thought I had posted an issue but didn't. Thanks for bringing that up ;)

rkingon commented 4 years ago

thanks!

yes, for now, i am using a render prop rather than using children.

children prop, however, is easier to iterate / clone.

i think the issue stems from the RouteComponents ability to have a nested structure, as seen here: https://reach.tech/router/api/RouteComponent (section: Children elements, Route Prop)