React - Router

route에 대해서

Posted by Yan on March 3, 2021

React Router

  • 리액트 라우터 v4는 더 이상 쿼리를 파싱하지 않는다. 하지만 this.props.location.search로 접근할 수 있다. 또는 useLocation도 있다.

  • this.props.location.search(?q1=dollar&qs2=yuan)같은 형태를 말하고,

let params = queryString.parse(this.props.location.search)

{ q1 : 'dollar', q2 : 'yuan }같은 형태를 돌려준다.

  • 만약 http://www.google.com.au?token=123의 query string을 받고 싶다면

const query = new URLSearchParams(this.props.location.search);한 후

1
2
const token = query.get("token");
console.log(token); //123

도움된 자료

stackoverflow