反应路线组件道具

时间:2020-11-11 04:28:13

标签: reactjs react-router react-router-dom react-router-v4 react-router-component

有人知道为什么您会用这种方式调用该组件。 () => <Component/>在路线内 enter image description here

2 个答案:

答案 0 :(得分:2)

您实际上并不需要这样做,但是,如果这样工作正常,我更喜欢这样:

<Route exact path="/business" component={BusinessLanding} />

我希望这消除了您的疑问,当您不想将任何道具传递给组件时,不需要调用() => <Component/>这样的组件

如果您想传递道具,可以这样:

<Route exact path="/business" component={({isOpen})=> <BusinessLanding open={isOpen} />} />

答案 1 :(得分:2)

如果您想传递新的道具(例如下面的示例isAuth)或从React Router访问道具(例如historylocationmatch

<Route component={({history, location, match}) => <Component isAuth={isAuth} />} />