InterviewHubPRO
Section Overview
Q83

Question 83 of 445

Part 2: React Router & Navigation (78 - 88)

19%
React & Modern Frontend (445 Qs)•Part 2: React Router & Navigation (78 - 88)

How to get query parameters in React Router v4?

The ability to parse query strings was taken out of React Router v4 because there have been user requests over the years to support different implementation. So the decision has been given to users to choose the implementation they like. The recommended approach is to use query strings library.

javascript
const queryString = require("query-string");
const parsed = queryString.parse(props.location.search);

You can also use URLSearchParams if you want something native:

javascript
const params = new URLSearchParams(props.location.search);
const foo = params.get("name");

You should use a polyfill for IE11.