我希望让这段代码工作,但在redux-router项目的源代码中没有通过文档或示例。我有以下代码(出于迁移原因,在/frontend中从根目录开始):
class App extends Component {
render() {
const links = [
'/frontend',
'/frontend/season',
'/frontend/episode'
].map(l =>
<p>
<Link to={l}>{l}</Link>
</p>
);
console.log('render');
return (
<div>
<h1>App Container</h1>
{links}
{this.props.children}
</div>
);
}
}
App.propTypes = {
children: PropTypes.node
};
function mapStateToProps(state) {
return {
routerState: state.router
};
}
connect(mapStateToProps)(App);
const rootReducer = combineReducers({
episode,
router: routerStateReducer
});
const store = compose(
reduxReactRouter({ createHistory})
)(createStore)(rootReducer,initialState);
class Root extends Component {
render() {
return (
<div>
<ReduxRouter history={history}>
<Route path="/frontend" component={App}>
<Route name="episode" path="episode" component={EpisodeApp} />
<Route name="season" path="season" component={SeasonApp} />
</Route>
</ReduxRouter>
</div>
);
}
}
React.render(
<Provider store={store}>
{() => <Root/>}
</Provider>
, document.getElementById('root'));问题是,当我按下链接时,什么都不会改变,应用程序也不会重新呈现它的子项,但当我使用浏览器导航来回切换时,它就可以工作了。我哪里搞砸了?
非常感谢!
发布于 2015-09-22 18:18:37
更新:
替换此行:
<ReduxRouter history={history}>通过这个(所以删除历史对象):
<ReduxRouter>让它工作,不知道为什么。
https://stackoverflow.com/questions/32706013
复制相似问题