React Route Component prop

Viewed 64
2 Answers

You don't really have to do it this but if that works its just fine, i prefer doing it this way:

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

I hope this clears your doubt that there is no need to call a component like this () => <Component/> when you dont want to pass any props to the component

If you want to pass props you can do it this way:

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

If you wanna pass new props (eg. isAuth below example) or access props from React Router (eg. history, location, match)

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