From 1a9d02702df66439f514bf8ec058fd479fa324af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=81=E6=B2=BB=E5=B9=B3?= Date: Mon, 24 Oct 2016 14:42:28 +0800 Subject: [PATCH] Route to controlled next path after local login --- src/common/components/forms/LoginForm.js | 9 +++------ src/common/utils/authRequired.js | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/common/components/forms/LoginForm.js b/src/common/components/forms/LoginForm.js index daf8023..05c5066 100644 --- a/src/common/components/forms/LoginForm.js +++ b/src/common/components/forms/LoginForm.js @@ -55,12 +55,8 @@ class LoginForm extends Component { if (json.isAuth) { this.login(json).then(() => { // redirect to the origin path before logging in - const { location } = this.props; - if (location && location.state && location.state.nextPathname) { - dispatch(push(location.state.nextPathname)); - } else { - dispatch(push('/')); - } + let { next } = this.props.routing.locationBeforeTransitions.query; + dispatch(push(next || '/')); }); } else { dispatch(pushErrors([{ @@ -110,4 +106,5 @@ export default reduxForm({ validate, })(connect(state => ({ apiEngine: state.apiEngine, + routing: state.routing, }))(LoginForm)); diff --git a/src/common/utils/authRequired.js b/src/common/utils/authRequired.js index 823b461..25eb3d9 100644 --- a/src/common/utils/authRequired.js +++ b/src/common/utils/authRequired.js @@ -4,8 +4,8 @@ export default (store) => (nextState, replace) => { if (!token) { replace({ pathname: '/user/login', - state: { - nextPathname: nextState.location.pathname, + query: { + next: nextState.location.pathname, }, }); }