reactjs - 使用flux-react-router发送道具
问题描述
我目前在我的 reactApp 中使用flux-react-router npm,并且在路由到url + 向组件发送道具时遇到问题。
这就是我路由到 url 的方式:onClick={()=>{ReactRouter.goTo( productpage/${item._id}
)}}
http://localhost:3000/productpage/5cb82c114e1efafcd06dc159
该 url 确实有效,但在我重新加载页面并重新渲染组件之前,该道具是未定义的。
我目前使用 window.location.href.split('/') 来获取 ID,但我想将它作为道具传递,但它似乎只在我重新渲染组件时才捕捉到道具,而不是在我路由到它时。
这是我在 index.js 中的组件
Flux.createRoute('/productpage/{id}',function(params){
ReactDOM.unmountComponentAtNode(document.getElementById('root'));
ReactDOM.render(<Provider store={store}><PersistGate loading={null} persistor={persistor}><ProductPage id={params.id}/></PersistGate></Provider>,document.getElementById('root'));
})
我只希望它在路由时发送道具,而不是重新加载页面来捕捉道具。
解决方案
推荐阅读
- c# - 将 XML 作为字符串处理的最佳方法
- hyperledger-fabric - Hyperledger Fabric - 单组织与多组织以及何时设置多组织环境?
- c++ - loadlibrary 失败,在 SDL2 中出现错误 -1073741795
- arrays - Ruby - 在哈希数组中设置键值对
- mongodb - Typegoose 对多态模型的绑定引用
- ruby-on-rails - 将 2 个对象传递给 RSpec 中的命名路由
- swift - 领域列表上的性能问题
- postgresql - 在 n 天内计算不同的用户
- javascript - 意外的令牌:尝试缩小 javascript 时的运算符 (>)?
- sails.js - 如何在sails.js >v1.0 中使用动态页面标题?