How to restrict access to routes in react-router?

Update (Aug 16, 2019) In react-router v4 and using React Hooks this looks a little different. Let’s start with your App.js. export default function App() { const [isAuthenticated, userHasAuthenticated] = useState(false); useEffect(() => { onLoad(); }, []); async function onLoad() { try { await Auth.currentSession(); userHasAuthenticated(true); } catch (e) { alert(e); } } return ( … Read more