react router中设置默认路由
程序员文章站
2024-02-13 20:33:22
...
1.引入所需插件
import {HashRouter as Router,Route,Redirect,Link,NavLink} from ‘react-router-dom’
2.设置默认路由
方法一
<Route path="/" component={MyTable} exact></Route>
<Route path="/myTable" component={MyTable}></Route>
方法二
<Redirect path="/" to="/myTable" />
<Route path="/myTable" component={MyTable}></Route>
方法2用 Redirect 会重定向url