reactjs - 使用 React-Router v4 在 Redux 应用程序中渲染 React 组件
问题描述
这是我第一次尝试将 React-Router4 集成到 React/Redux 应用程序中。在阅读文档和一篇(非常好的)CSS-Tricks 文章时,我已经被困在第一个障碍上几个小时了。
问题是不会呈现我在组件道具中输入的“任何”值,它应该是一个组件。
我实际上几乎完全通过(优秀)文档阅读,从这里开始:https ://reacttraining.com/react-router/web/guides/quick-start
我已经查阅了这篇文章:https : //css-tricks.com/react-router-4/ 其中还包括这个 Codepen(看看我是否做了一些明显/愚蠢的事情): https ://codepen.io/bradwestfall /project/editor/XWNWge?preview_height=50&open_file=src/app.js
我只是希望 SO 上的某个人能够推动我度过这个难关。我希望至少能够非常简单地呈现这个,而不需要任何额外的库或基于以下内容对我的商店进行调整: https ://reacttraining.com/react-router/web/guides/redux-integration
入口点,index.js:
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import store from './stores'
import { Provider } from 'react-redux'
import Home from './components/Home'
import TopStories from './components/TopStories'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
// app entry point
const app = (
<Provider store={store.configure(null)}>
<Router>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/topstories" component={TopStories} />
</Switch>
</Router>
</Provider>
)
// virtual DOM render
ReactDOM.render(app, document.getElementById('root'))
TopStories.js 组件(如果我用 Home 切换它,则在“/”路径中呈现正常)
import React, { Component } from 'react'
export default (props) => {
return(
<div>Top Stories component </div>
)
}
解决方案
我试图通过在浏览器中输入路径来进行测试.... Duh。我只需要设置一个快速链接组件,一切正常。
推荐阅读
- python - 小部件是否可以有标准样式?
- c - struct 和 union 是如何使用内存的?
- sublimetext3 - Sublime:快速检查文件在哪里使用?
- ios - Firebase 电子邮件验证重定向网址
- xamarin.forms - MBProgressHUD 水平进度条 xamarin ios
- c# - 动态表达EF核心“点赞”功能
- arrays - 从 Firestore 中的数组中删除对象
- javascript - 在后端生成由 Javascript (VueJS) 生成的等效 HTML
- ios - 如何正确对齐这些 collectionview 单元格?
- blockchain - 状态演化的架构问题