I need the answer to this question: Render multiple components in React Router but for the newer version of react-router-dom (I'm using v6.0.2)
the older version of router-dom would work like this:
<Route path="/">
<Header/>
<Home/>
</Route>
while the new one looks like this:
<Route exact path="/" element={<Home/>}/>
I'm not sure how to add the Header as well
Try wrap them in a fragment
<Route exact path="/" element={<><Header/><Home/></>}/>
I ran in to the same issue, but also needed one page to get data from the parent element.
<Route path="/" element={<><Header/><Home children={<HomeDataProvider/>}/></>} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With