【发布时间】:2016-12-26 19:59:47
【问题描述】:
使用“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:
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
)
);
【问题讨论】:
标签: reactjs redux react-router react-redux react-router-redux