不在react-router中的sessionStorage中存储自定义状态

时间:2016-04-16 13:45:08

标签: react-router history.js

我正在使用路由上的onEnter功能在前端添加一些授权逻辑。具体来说 -

  1. 如果未经授权的用户登陆需要授权的页面,请将nextPath存储在新位置状态nextPathname中,并将用户重定向到登录页面。登录时,用户将被重定向到nextPathname。在这里,我明确地将nextPathname存储在redux-store中。
  2. function requireAuth(nextState, replace) { if (!s.isLoggedIn(store.getState())) { replace({ pathname: '/login', state: { nextPathname: nextState.location.pathname } }) } }

    1. 如果未经批准的用户登陆他不被允许的页面,请将路径名称存储在unauthroizedPathname,并将用户带到新页面并显示包含页面名称的相关错误消息。在这里,我只是在几秒钟后显示错误消息并解散。
    2. ````

      function requireValidation(nextState, replace) {
        if (!s.isFinancierVerified(store.getState())) {
          replace({
            pathname: '/dashboard',
            state: { unauthroizedPathname: nextState.location.pathname }
          })
        }
      }
      

      ````

      我需要这些状态仅存在于nextPath而不是之后。但是,看起来这些状态保存在sessionStorage中,因此即使通过页面重新加载也会保持这些状态。

      有没有办法可以禁用这些状态存储在sessionStorage中?或者我可以通过任何其他方式完成上述任务?

      Custom states stored in session storage

0 个答案:

没有答案
相关问题