-
-
Save Nilanth/13bc704df041413cff77ca9c56608682 to your computer and use it in GitHub Desktop.
Public Routes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Route, | |
Redirect | |
} from 'react-router-dom'; | |
function PublicRoute({ children, isAuthenticated, ...rest }) { | |
return ( | |
<Route | |
{...rest} | |
render={ | |
({ location }) => ( | |
!isAuthenticated ? ( | |
children | |
) : ( | |
<Redirect | |
to={{ | |
pathname: '/home', | |
state: { from: location } | |
}} | |
/> | |
)) | |
} | |
/> | |
); | |
} | |
export default PublicRoute; |
@gordielachance i've solved it by passing the props component=Component as comp=Component
But, does this work for you? the whole code?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I get this warning:
Warning: You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored