通过 React Router 传递 state 和 props [英] Passing state and props through React Router

查看:51
本文介绍了通过 React Router 传递 state 和 props的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过反应路由器将应用程序状态传递给子组件.经过几个星期的使用 redux,我得出的结论是,为此目的处理 redux 令人难以置信的复杂和令人沮丧.我发现自己安装了越来越多的软件包来解决它的缺点.我尝试在路由器上使用 redux,结果发现我现在需要安装 react-redux-router.然后是@connect 在打字稿中不起作用的问题,需要更多的解决"功能和样板.在这一点上,我几乎觉得我应该将值存储在一个隐藏的输入中.

I'm trying to pass the application state through a react router to to the child components. After several weeks of messing with redux I've come to the conclusion that redux is incredibly convoluted and frustrating to deal with for this purpose. I'm finding myself installing more and more packages to deal with its shortcomings. I tried using redux across the router, only to realize that I now need to install react-redux-router. Then there's the issue with @connect not working in typescript, requiring more "work around" functions and boilerplate. At this point I almost feel like I should just store the values in a hidden input.

难道没有一种简单的方法可以通过路由器向下传递应用程序状态吗?从我读过的内容来看,这在简单的反应中是不可能的.

Is there not a simple way to pass the application state down through the router? From what I've read this isn't possible in plain react.

推荐答案

这在 React 中绝对是可能的.这是一个简单的代码示例:

This is definitely possible in React. Here's a simple code example:

<Route path="/example" render={() => {
    return <Child someProps={someValue} />;
}} />

这篇关于通过 React Router 传递 state 和 props的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆