Programmatically Navigate using react-router

前端 未结 8 1322
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:07

I am developing an application in which I check if the user is not loggedIn. I have to display the login form, else dispatch an action

8条回答
  •  梦如初夏
    2020-11-21 23:32

    This is my handle loggedIn. react-router v4

    PrivateRoute is allow enter path if user is loggedIn and save the token to localStorge

        function PrivateRoute({ component: Component, ...rest }) {
         return (
             (localStorage.token) ?  : (
                
              )
              }
            />
          );
        }
    

    Define all paths in your app in here

    export default (
      
    );

提交回复
热议问题