Dynamic Routing에서 props 가져올 때
2021. 7. 27. 14:53ㆍReact
https://localhost:3000/about?name=mark
에서 mark를 가져오고 싶을 때
1. URLSearchParams 사용(브라우저에 따라 동작 안할 수 있음)
const searchParams = props.loacation.search;
const obj = new URLSearchParams(searchParams);
console.log(obj.get("name"));
2. query-string 사용
설치 npm i query-string -S
사용법
const query = queryString.parse(searchParams);
console.log(query.name);
'React' 카테고리의 다른 글
React Reconciliation (0) | 2021.07.30 |
---|---|
react-router-dom Redirect (0) | 2021.07.27 |
react-router-dom에서 페이지 이동시 Link component 사용 (0) | 2021.07.27 |
react-router-dom Switch component, NotFound (0) | 2021.07.27 |
React State Handling (0) | 2021.07.24 |