Redirect using react-router in redux middleware

后端 未结 2 1570
北荒
北荒 2021-02-10 14:45

I\'ve created a middleware that checks if a request returns an invalid access response. If the status is a 401, I want to redirect the user to the login page

Here\'s the

2条回答
  •  情话喂你
    2021-02-10 15:13

    use onEnter method of react-router. call a function which will check for the access. Example:

    function checkAccess() {
       //some logic to check 
        if(notAuthorized){ window.location.href= "/login"; }
      }
    

提交回复
热议问题