Using React, Redux and React-router, I want to to bind different components to the same route depending on the redux state. for example:
Assuming ComponentA and ComponentB are React components
Assuming I have this redux state
{
flag: true;
}
I want to have this React Router configuration /routes.js
<Route path="/" component={App}>
<Route path="/test" component={ComponentA} />
</Route>
but if I have the flag
in my Redux state to be false
I want to have
...
<Route path="/test" component={ComponentB} />
...
I am aware that I can create a wrapper component to ComponentA
and ComponentB
that checks the redux state and then render the corresponding component, but I was searching for an answer that doesn't require creating new components