How to parse a query string in React Router

后端 未结 3 1736
不思量自难忘°
不思量自难忘° 2021-02-20 08:39

Hello I´m using react router and I need to pass some querystring parameters

tried with



        
3条回答
  •  鱼传尺愫
    2021-02-20 09:25

    You need to use the library you don't need to add the query string in the Route:

    Here is an example:

    import React from "react"; var qs = require("qs");

    const Home = props => {
      console.log(props.location.search);
      const query = qs.parse(props.location.search, {
        ignoreQueryPrefix: true
      });
      console.log(query);
      return (
        

    Welcome to the Tornadoes Website!

    ); }; export default Home;

    CodesandBox Example: https://codesandbox.io/s/a-simple-react-router-v4tutorial-mw9b4

提交回复
热议问题