how to use switch in react router code example
Example 1: switch in react
renderSwitch(param) {
switch(param) {
case 'foo':
return 'bar';
default:
return 'foo';
}
}
render() {
return (
<div>
<div>
// removed for brevity
</div>
{this.renderSwitch(param)}
<div>
// removed for brevity
</div>
</div>
);
}
Example 2: how to export switch from react-router-dom
let routes = (
<Fade>
<Switch>
{/* there will only ever be one child here */}
<Route />
<Route />
</Switch>
</Fade>
);
let routes = (
<Fade>
{/* there will always be two children here,
one might render null though, making transitions
a bit more cumbersome to work out */}
<Route />
<Route />
</Fade>
);