React Route Componentから別のReact Route Componentにオブジェクトを送信する方法を見つけることができません。例えば 私はこのようなコンテナのルータがあります。このようなHome
コンポーネントでReact Routes間で小道具を渡す方法
const App =() => (
<Router>
<div>
<Route exact path="/" component={Home} />
<Route path="/sections/:id"
component={Section} />
</div>
</Router>
)
を:
const Home =() => {
const Sections = tilesData.map((section, index) => (
<div>
<img src={section.img} height="200" /><br/>
<Link to={`/sections/'${section.id}`} >Details for {section.author}</Link>
<hr/>
</div>
))
return(
<div>
{Sections}
</div>
)
}
と、私は次のルートが<Link>
をクリックしたときに、選択したオブジェクトを渡す方法を\ =理解していません。ここでは例の構成要素である:ここで
const Section = (props) => {
return(
<div>
Section {props.title}
<img src={props.img} />
</div>
)
}
はコードの例です:
https://codesandbox.io/s/Mv037AE3
あなたは 'react-redux'を使用し、店舗のデータを持っていて、あるコンポーネントから別のコンポーネントに渡すのではなく、IDを使って店舗のデータにアクセスできます。このようにして、データは集中管理され、すべてのコンポーネントにアクセスできます。 – Aruna
ええ、おそらくあなたが正しいです&私はより良い "反応redux'と固執します。ありがとう!) – Jamland