This question is already asked here but in another context, and for another purpose.
Dependencies:
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.2.2"
Suppose I have the following routing structure:
<Route path='/' element={<Outlet />}>
<Route path='SystemFile' >
<Route index element={<Navigate to="HospitalInfo" />} />
<Route path='HospitalInfo' element={<HospitalInfoWithTabs tabPages={tabs} />} />
<Route path='HospitalControls' element={<HospitalControlsWithTabs tabPages={tabs} />} />
<Route path='LabControls' element={<LabControlsWithTabs tabPages={tabs} />} />
<Route path='*' element={<Navigate to="HospitalInfo" />} />
</Route>
</Route>
My purpose is to extract the entire "System File" sub-tree, and export it from another file called "SystemFile.jsx", as follows:
export function SystemFileRoutes() {
return (
<Route path='SystemFile' >
<Route index element={<Navigate to="HospitalInfo" />} />
<Route path='HospitalInfo' element={<HospitalInfoWithTabs tabPages={tabs} />} />
<Route path='HospitalControls' element={<HospitalControlsWithTabs tabPages={tabs} />} />
<Route path='LabControls' element={<LabControlsWithTabs tabPages={tabs} />} />
<Route path='*' element={<Navigate to="HospitalInfo" />} />
</Route>
)
}
And then reuse it inside the original route:
<Route path='/' element={<Outlet />}>
<SystemFileRoutes />
</Route>
This is yielding to the following error : "All component children of Routes must be a Route or React.Fragment"
Your help is appreciated.