3
如何在使用“react-router-redux”时获取当前位置?从react-router-redux获取当前位置
这是routing
状态:
{
routing: {
locationBeforeTransition: {
pathname: "/foo",
search: "",
hash: "",
state: null,
action: "PUSH",
key: "e8jfk"
},
query: null,
$searchBase: {
search: "",
searchBase: ""
}
}
}
我可以明确地为state.routing.locationBeforeTransition.pathname
访问当前的位置,但名称“locationBeforeTransition”看起来这将是之前的页面位置,而不是当前的一个。这似乎也很奇怪,这是我的路由状态中唯一的属性。我怀疑我做错了什么。
这里是一个简化的减速器,只有具有路由:
reducer.js
import { combineReducers, createStore, applyMiddleware, compose } from 'redux';
import { routerReducer, routerMiddleware } from 'react-router-redux';
import { browserHistory } from 'react-router';
import thunkMiddleware from 'redux-thunk';
const reducer = combineReducers({
routing: routerReducer,
});
export const store = createStore(reducer, {}, compose(
applyMiddleware(
routerMiddleware(browserHistory),
thunkMiddleware
),
window.devToolsExtension ? window.devToolsExtension() : f => f
)
);