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