Answer the question
In order to leave comments, you need to log in
React Router 4. (Switch/Route/Redirect). How to switch to Route in the same Switch when redirecting?
Hi guys!
There is a category component. This is the parent component (! not inheritance !just redirects to them with passing properties) for FormCategory&ListCategory. Both components have their own base classes - FormComponent&ListComponent - in which the common logic lies.
Category code (render method):
render() {
return <Switch>
<Route path='/category/list' render={() => this.getCategoryListWithBinding()} />
<Route path='/category/form/:id' render={() => this.getCategoryFormWithBinding()} />
</Switch>
}
render() {
return (
<Layout>
<Switch>
<Route exact path='/' component={Home} />
<Route path='/counter' component={Counter} />
<Route path='/fetchdata' component={FetchData} />
<Route path='/category' history={this.history} component={CategoryComponent} />
<Route path='/products' history={this.history} component={ProductComponent} />
</Switch>
</Layout>
);
}
Answer the question
In order to leave comments, you need to log in
render() {
return (
<Switch>
<Route path='/category/list' render={() => this.getCategoryListWithBinding()} />
<Route path='/category/form/:id' render={() => this.getCategoryFormWithBinding()} />
<Redirect to='/category/list' />
</Switch>
);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question