I'm new on React and I'm facing the error "Uncaught Error: [BrowserRouter] is not a component. All component children of must be a or <React.Fragment>".
I'm trying to do a private route to avoid users to land on the dashboard without being loged on.
PrivateRoute.js
export default function PrivateRoute({ component: Component, ...rest }) {
const { currentUser } = useAuth()
return (
<Route
{...rest}
render={props => {
return currentUser ? <Component {...props} /> : <Route path="/" element={<Navigate to='/login' replace />} />
}}
></Route>
)
}
App.js
function App()
return(
<Container
className="d-flex align-items-center justify-content-center"
style={{minHeight: "100vh"}}
>
<div className="w-100 " style={{ maxWidth: '400px'}}>
<Router>
<AuthProvider>
<Routes>
<Route element={<PrivateRoute/>} >
<Routes>
<Route path='/' element= {<Dashboard />}/>
</Routes>
</Route>
<Route path="/signup" element={<Signup />}/>
<Route path="/login" element={<Login />}/>
</Routes>
</AuthProvider>
</Router>
</div>
</Container>
)
}
I don't know what to do and can't find info about this specific problem, please explain me like I'm 5