I can't understand why there is no replace
method in getComponent
.
My usecase is as follows. In positive case I need a redirect to different route, in negative case I need to render a component in place:
if true, / =redirect=> /green
if false, render Red right here /
<Route path="" component={App}>
<Route path="/" getComponent={(nextState, cb) => {
if(true) {
replace('green') // but there is no replace() here in getComponent(). Why?
cb(null);
}
else {
cb(null, Red)
}
}}>
</Route>
</Route>
How to achieve it? You provide two methods, onEnter
and getComponent
. But neither solves this use case. How does react-router
suppose to solve this typical use case?
Because that is not the correct place to be redirecting. Use an onEnter hook for this.
How did you identify it is not a right place? I've just provided you with an example how a right place it is.
replace
function in getComponent
function?Use an onEnter hook for this.
Most helpful comment
Because that is not the correct place to be redirecting. Use an onEnter hook for this.