Skip to content

Instantly share code, notes, and snippets.

@Wellers0n
Created May 27, 2019 14:04
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 Wellers0n/0cc2cfc942d51bba9b384fec003b1e06 to your computer and use it in GitHub Desktop.
Save Wellers0n/0cc2cfc942d51bba9b384fec003b1e06 to your computer and use it in GitHub Desktop.
private Router
// privateRouter.js
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import {isAuthenticated} from './../auth'
const PrivateRouter = ({component: Component, ...rest}) => {
return (
<Route {...rest} render={(props) => (
isAuthenticated() ? (
<div>
<Component {...props}/>
</div>
) : <Redirect to="/"}/>
)} />
)
}
export default PrivateRouter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment