title: React - Routing & Redirect after login to attempted page
body: <p>What is best practice to implement react-router 4? Currently I created two components, <code>PrivateRoute</code> and <code>PublicRoute</code>. <code>PublicRoute</code> is for <code>/login</code> path and it renders <code>Login</code> component, and <code>PrivateRoute</code> is for rest of paths and it renders passed Component if user is logged or does redirect. <code>PrivateRoute</code> code is:</p>
  
  <pre><code>const PrivateRoute = ({component: Component, ...rest}) =&gt; (
  &lt;Route {...rest} render={(props) =&gt; (
      helpers.getCurrentUser()
          ? (
              &lt;div className="wrapper"&gt;
                  &lt;Sidebar/&gt;
                  &lt;div id="content"&gt;
                      &lt;Navbar/&gt;
                      &lt;Component {...props}/&gt;
                      &lt;Footer/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          ) :
          &lt;Redirect
              to={{
                  pathname: "/login",
                  state: {from: props.location}
              }}
          /&gt;
  )}/&gt;
  </code></pre>
  
  <p>);</p>
  
  <p>And <code>Router</code> component in same file is:</p>
  
  <pre><code>export default () =&gt; (
  &lt;Router history={history}&gt;
      &lt;Switch&gt;
          &lt;Route exact path={'/login'} component={PublicRoute}/&gt;
          &lt;PrivateRoute exact path={"/"} component={Dashboard}/&gt;
          &lt;PrivateRoute exact path={"/users"} component={UsersComponent}/&gt;
          &lt;PrivateRoute exact path={"/logs"} component={LogsComponent}/&gt;
          &lt;PrivateRoute exact path={"/project"} component={ProjectComponent}/&gt;
          &lt;PrivateRoute exact path={"/user"} component={UserComponent}/&gt;
      &lt;/Switch&gt;
  &lt;/Router&gt;
  </code></pre>
  
  <p>);</p>
  
  <p>How to implement redirection to attempted page if not logged?</p>