redirect-auth-wrapper问题与重定向返回 - 始终重定向到主页

时间:2017-10-06 19:16:14

标签: reactjs react-redux

我正在开发一个应用程序,我在重新定位redux-auth-wrapper时遇到了问题,我遵循了docuemntation,但我得到了这个问题,我总是在登录后回家,例如:

我访问:

 http://localhost:3000/admin

我被重定向到:

 http://localhost:3000/login?redirect=%2Fadmin it's ritght!

但登录后我被重定向到

 http://localhost:3000/

登录后如何进入/ admin?

我的版本:

"react-redux": "4.4.5",
"react-router": "3.2.0",
"react-router-redux": "4.0.6",
"redux": "3.6.0",
"redux-auth-wrapper": "2.0.2",

我的auth.js:

import locationHelperBuilder from 'redux-auth-wrapper/history3/locationHelper'
import { connectedRouterRedirect } from 'redux-auth-wrapper/history3/redirect'
import { routerActions } from 'react-router-redux'

import { Loading } from './components'

const locationHelper = locationHelperBuilder({})

export const userIsAuthenticated = connectedRouterRedirect({
  redirectPath: '/login',
  authenticatedSelector: state => state.auth.isAuthenticated,
  authenticatingSelector: state => state.auth.isLoading,
  AuthenticatingComponent: Loading,
  redirectAction: routerActions.replace,
  wrapperDisplayName: 'UserIsAuthenticated'
})

export const userIsAdmin = connectedRouterRedirect({
  redirectPath: '/',
  allowRedirectBack: false,
  authenticatedSelector: state => state.auth.data !== null && state.auth.data.isAdmin,
  redirectAction: routerActions.replace,
  wrapperDisplayName: 'UserIsAdmin'
})

export const userIsNotAuthenticated = connectedRouterRedirect({
  redirectPath: (state, ownProps) => locationHelper.getRedirectQueryParam(ownProps) || '/foo',
  allowRedirectBack: false,
  // Want to redirect the user when they are done loading and authenticated
  authenticatedSelector: state => state.auth.data === null && state.auth.isLoading === false,
  redirectAction: routerActions.replace,
  wrapperDisplayName: 'UserIsNotAuthenticated'
})

我的routes.js:

import React from 'react';
import { Route , IndexRoute } from 'react-router';
import App from './components/App';
import LoginPage from './containers/LoginPage';
import LogoutPage from './containers/LogoutPage';
import AdminPage from './containers/AdminPage';

import SelectSolution from './containers/SelectSolution';

import AboutPage from './components/AboutPage.js';
import NotFoundPage from './components/NotFoundPage.js';

import { userIsAuthenticated
       // , userIsAdmin
       // , userIsNotAuthenticated 
       } from './auth'


export default (
  <Route path="/" component={App}>
    <IndexRoute component={SelectSolution}/>
    <Route path="login" component={LoginPage}/>
    <Route path="logout" component={LogoutPage}/>
    <Route path="admin" component={userIsAuthenticated(AdminPage)}/>
    <Route path="about" component={AboutPage}/>
    <Route path="*" component={NotFoundPage}/>
  </Route>
);

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

很抱歉,我的登录组件是:

componentWillReceiveProps(newProps) {
   if (newProps.pageState.auth.isAuthenticated) {
     this.props.router.replace('/');
   }
}

我希望你能道歉我!!!!