+1 vote
in ReactJS by

How to get query parameters in React Router v4?

1 Answer

0 votes
by

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.

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

You can also use URLSearchParams if you want something native:

const params = new URLSearchParams(props.location.search)
const foo = params.get('name')

You should use a polyfill for IE11.

Related questions

+1 vote
asked Mar 2, 2020 in ReactJS by RShastri
0 votes
asked Dec 14, 2023 in ReactJS by rahuljain1
...