React - How to get parameter value from query string?

后端 未结 30 2228
温柔的废话
温柔的废话 2020-11-22 10:22

How can I define a route in my routes.jsx file to capture the __firebase_request_key parameter value from a URL generated by Twitter\'s single sign on process a

30条回答
  •  梦谈多话
    2020-11-22 10:59

    React Router v4 no longer has the props.location.query object (see github discussion). So the accepted answer will not work for newer projects.

    A solution for v4 is to use an outside library query-string to parse the props.location.search

    const qs = require('query-string');
    //or
    import * as qs from 'query-string';
    
    console.log(location.search);
    //=> '?foo=bar'
    
    const parsed = qs.parse(location.search);
    console.log(parsed);
    //=> {foo: 'bar'}
    

提交回复
热议问题