Skip to content

Instantly share code, notes, and snippets.

@Nilanth
Last active February 15, 2022 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nilanth/13bc704df041413cff77ca9c56608682 to your computer and use it in GitHub Desktop.
Save Nilanth/13bc704df041413cff77ca9c56608682 to your computer and use it in GitHub Desktop.
Public Routes
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
Copy link

gordielachance commented Feb 15, 2022

I get this warning:

Warning: You should not use <Route component> and <Route render> in the same route; <Route render> will be ignored

@malks14
Copy link

malks14 commented Feb 15, 2022

@gordielachance i've solved it by passing the props component=Component as comp=Component

https://stackoverflow.com/questions/57408430/warning-you-should-not-use-route-component-and-route-render-in-the-same-rou

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