读取当前URL的查询参数

时间:2018-03-30 18:04:48

标签: reactjs

我有这样的网址http://localhost/validateemail?email=abc@yahoo.com&token=12345

如何在componentWillMount()函数中读取查询参数email和token?

导入React,{Component}来自'反应&#39 ;;

export default class ValidateEmail extends Component{

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

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

有人可以指导我。

1 个答案:

答案 0 :(得分:0)

您可以使用const query = new URLSearchParams(this.props.location.search)

这将为您提供查询参数的对象。

要从中获取单个条目,您可以const foo = query.get(foo)

相关问题