I'm trying to create a wrapper for the Route component of React Router, something like this:
import { Navigate, Route } from 'react-router-dom'
function MSRoute({ path, element, isStaff = false }) {
return (
<>
{ isStaff
? (
<Route
path={path}
element={element}
/>
) : (
<Route
path="*"
element={<Navigate to="/" />}
/>
)
}
</>
)
}
export default MSRoute
Basically because I need to restrict some routes for certain types of users, but I'm getting the following error:
Uncaught Error: [MSRoute] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
Is there any way of doing this? Any clean workaround?
regards