I am building a simple application using React Router. Here is the code which I currently have:
function App() {
return (
<Routes>
<Route path='/Login' element={<Login />}></Route>
<MyRoute />
</Routes>
)
}
const MyRoute = (props) => {
return <Route path='/Dashboard' element={<Dashboard />}/>
}
export default App
Whenever I do this I am getting the following error:
utils.ts:757 Uncaught Error: [ProtectedRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
at invariant (utils.ts:757:1)
at components.tsx:563:1
at react.development.js:1195:1
at react.development.js:1158:1
at mapIntoArray (react.development.js:1049:1)
at mapIntoArray (react.development.js:1099:1)
at mapChildren (react.development.js:1157:1)
at Object.forEachChildren [as forEach] (react.development.js:1194:1)
at createRoutesFromChildren (components.tsx:547:1)
at Routes (components.tsx:379:1)
But if I return the actual Route component then there is no error. My doubt is that why isn't this working even when I am returning a Route
element from MyRoute
?
Please comment if more information is needed.