当访问者访问我的网站时,如果他们未登录,则会将他们重定向到登录页面。这是由onEnter()完成的(见下面的代码)。当重定向发生时,我想访问并存储原始路径。但不知怎的,我不断从redux商店获得后重定向路径,即store
。我怎样才能得到原版的?
这是我的routes.js中的简化代码(我也使用redux,因此...
export default (store) => {
const requireLogin = (nextState, replace, cb) => {
function checkAuth() {
const { auth: {loggedIn} } = store.getState();
if (!loggedIn) {
replace('/login');
}
cb();
}
console.log(store.getState().routing.location.path); // here I always get the post-redirect path as opposed to the pre-redirect path
if (!isAuthLoaded(store.getState())) {
store.dispatch(loadAuth()).then(checkAuth);
} else {
checkAuth();
}
};
return (
<Route path="/" component={App}>
<Route onEnter={requireLogin}>
<Route path="postLoginPage" component={postLoginPage} />
</Route>
<Route path="login" component={Login} />
</Route>
);
};
)。
var babelifyOptions = {
presets: ['es2015', 'stage-0', 'react'],
extensions: ['.js', '.jsx']
};