react-router-dom重定向

<Switch>
    <Route exact path="/app/" render={() => 
    <Redirect to='/app/error'></Redirect>}></Route>
    <Route path="/app/users" component={Users}></Route>
    <Route path="/app/report" component={Report}></Route> 
    <Route path="/app/error" component={ErrorPage}></Route>
    <Redirect to="/app/" />
</Switch>

如上代码中:

1:/app/users 地址栏输入,跳转到指定的Users组件

2:exact 指定输入/app/重定向redirect to (/app/error),重定向到ErrorPage组件中

3:如果输入错误的地址,重定向到/app/的路由,跳转到ErroPage组件中

注意:如上重定向(有指定重定向,和模糊重定向)

猜你喜欢

转载自blog.csdn.net/hahahhahahahha123456/article/details/81701065