1

I have url like this http://localhost/validateemail?email=abc@yahoo.com&token=12345

How can I read the query parameters email and token inside componentWillMount() function?

import React,{Component} from 'react';

export default class ValidateEmail extends Component{

  constructor(props){
    super(props);
  }
  componentDidMount(){
  //  alert(this.props.match.params.token);
  }

  render(){
    return(
      <div>Validate email</div>
    );
  }
}

can someone please guide me.

hitesh
  • 449
  • 3
  • 11
  • 26
  • Have you tried https://stackoverflow.com/questions/42862253/how-to-parse-query-string-in-react-router-v4? – BenR Mar 30 '18 at 18:07
  • Possible duplicate of [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – sibnerian Mar 30 '18 at 19:19

1 Answers1

0

You can use const query = new URLSearchParams(this.props.location.search).

This will give you an object of your query parameters.

To get a single entry out of this you can const foo = query.get(foo)

Jonathan R
  • 3,652
  • 3
  • 22
  • 40