有人知道为什么您会用这种方式调用该组件。 () => <Component/>
在路线内
enter image description here
答案 0 :(得分:2)
您实际上并不需要这样做,但是,如果这样工作正常,我更喜欢这样:
<Route exact path="/business" component={BusinessLanding} />
我希望这消除了您的疑问,当您不想将任何道具传递给组件时,不需要调用() => <Component/>
这样的组件
如果您想传递道具,可以这样:
<Route exact path="/business" component={({isOpen})=> <BusinessLanding open={isOpen} />} />
答案 1 :(得分:2)
如果您想传递新的道具(例如下面的示例isAuth
)或从React Router访问道具(例如history
,location
,match
)
<Route component={({history, location, match}) => <Component isAuth={isAuth} />} />