I want to use private route with react-router-dom v6, while i am trying to apply a condition for auth.
In App.js
<Route path='/dashboard' element= { <PrivateRoute><Abc /></PrivateRoute>}/>
In a component .js
<Routes> <Route {...rest} render={props => !isAuthenticated && !loading ? (<Navigate to='/login' />) : (<Component {...props} />)} /></Routes>
- When the Route is not inside <Routes> it gives an error:
Error: A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your in a <Routes>
- When it is inside <Routes> it give an error as:
Error: [Abc] is not a <Route> component. All component children of must be a <Route> or <React.Fragment>
Pls help me to resolve this situation ? Or any suggestion.
Tried this but one of the above error in both cases
<Route path='/dashboard' element= {<PrivateRoute> <Dashboard />
</PrivateRoute>}/>
Also
`<PrivateRoute path='/dashboard' element= { <Dashboard />}/>`
PICCode full