【发布时间】:2018-04-15 18:32:15
【问题描述】:
我在 redux 应用中使用 react-router-dom。
这是我在 index.js 中的初始设置:
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
, document.getElementById('root'));
然后在我的 App.js 中有:
render() {
return (
<div className="App">
<Route exact path="/" render={ () => {
return (
<div>
{
this.props.categories.map((category)=>{
console.log('category', category)
return (
<Link key={category.name} to="/category" >{category.name}</Link>
)
})
}
</div>
)
}}
/>
<Route path="/category" render={ () => {
console.log('category path this.props', this.props)
return (<p>Category is whatever</p>)
}}
/>
</div>
);
}
我认为每当我点击任何显示的链接时,浏览器都会自动知道如何呈现新的路由路径/类别,但由于某种原因它不知道。
我做错了什么?
【问题讨论】:
-
我使用 create-react-app 尝试了您的代码,效果很好。你使用的是 create-react-app 还是 webpack-dev-server?
-
create-react-app 我正在使用 Redux
-
这是应该包含在问题/问题中的其他代码:export default connect(mapStateToProps,)(App)
-
你的工作可能是因为它是普通的旧 React 而不是 React with Redux ...这是我的猜测...
标签: reactjs react-redux react-router-redux react-router-dom