react --- 路由跳转、路由传参

一、路由跳转
1、a标签跳转

 import { Link } from "react-router-dom";
<Link to="/map">go map</Link>

2、js跳转

this.props.history.push("/map");

一、路由传参
1、state(不消失)

// 传
this.props.history.push({ pathname: '/fag',state:{id:6666}});
// 取
console.log(this.props.location.state.id)

2、params(不消失)

{
    path: "/fag/:id",
    component: Faq,
}
this.props.history.push({ pathname: `/fag/${6666}`});
console.log(this.props.match.params.id)

3、query(会消失)

this.props.history.push({ pathname: '/fag',query:{id:6666}});
console.log(this.props.location.query.id)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容