- 路由模式(hash、h5 history),同 vue-router
- 路由配置(动态路由、懒加载),同 vue-router
<Router>
<Switch>
<Router exact path="/">
<Home />
</Router>
<Router path="/project/:id">
<Project />
</Router>
<Router exact path="*">
<NotFound />
</Router>
</Switch>
</Router>
import { Link, useParams, useHistory } from 'react-router-dom';
function Project() {
const { id } = useParams();
// 获取参数 例如 /project/100
<Link to="/">首页</Link>
}
let his = useHistory();
his.push('/');