In react, switch is used to ensure that the route only renders one path, and is used to solve the unique rendering of the route; when using the "
" package, it will stop after matching a path. Rendering, if you do not use the " " package, each matched " " will be rendered.
The operating environment of this tutorial: Windows 10 system, react version 17.0.1, Dell G3 computer.
Every matched
In order to solve the unique rendering of route, it is to ensure that the route only renders one path.
If
<Router history={history}> <Switch> <Route path='/home' render={()=>(<div>首页</div>)}/> <Route path='/home' component={()=>(<div>首页</div>)}/> </Switch> </Router>
If
<Router history={history}> <Route path='/home' render={()=>(<div>首页</div>)}/> <Route path='/home' render={()=>(<div>首页</div>)}/> </Router>
react video tutorial"
The above is the detailed content of What is the usage of switch in react. For more information, please follow other related articles on the PHP Chinese website!