React 向url中添加参数

时间:2025-02-07 21:16:22
  • 用@withRouter修饰组件,把不是通过路由切换过来的组件中,将react-router 的 history、location、match 三个对象传入props对象上
  • 使用queryString去序列化需要添加的参数:
    ({
    	name:liff,
    	id:1111
    })
    // return name=liff&id=1111
    
  • 在props中获取history,并且把序列化的后的参数push进去
    import queryString from "query-string";
    import {withRouter} from "react-router-dom";
    ({
    	({
    		name:liff,
    		id:1111
    	})
    })
    
  • 相关文章