Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react parameter value from query string

// As far as I know there are three methods you can do that.
// Suppose an URL looks like this
// http://www.google.com.au?token=123

// 1) use a third library called 'query-string'.
import queryString from 'query-string'

const value=queryString.parse(this.props.location.search);
const token=value.token;
console.log('token',token)//123

// 2) Without library - Get a single query string
const query = new URLSearchParams(this.props.location.search);

const token = query.get('token')
console.log(token)//123

// 3) One liner - Get query string with '&' and without any library
const getQueryParams = () => window.location.search.replace('?', '').split('&').reduce((r,e) => (r[e.split('=')[0]] = decodeURIComponent(e.split('=')[1]), r), {});
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to use hidden in div in angular 
Javascript :: call javascript function after page load complete 
Javascript :: npm md5 
Javascript :: shuffle an array of numbers in javascript 
Javascript :: divide first name and last name in javascript 
Javascript :: How to get all input fields inside div with JavaScript 
Javascript :: wordpress load latest jQuery 
Javascript :: javascript video feed 
Javascript :: js convert special characters to html entities 
Javascript :: check all values from keys in object js 
Javascript :: jquery selector partial class name 
Javascript :: remove current table row in jquery 
Javascript :: button in javascript 
Javascript :: logout user firebase 
Javascript :: Codewars JS Multiples of 3 or 5 
Javascript :: last week date js 
Javascript :: crop image canvas 
Javascript :: how do you make a random array in javascript 
Javascript :: fetch javascript 
Javascript :: nohup run nodejs 
Javascript :: send message whatsapp javascript 
Javascript :: login page link shopify 
Javascript :: regex not contain 
Javascript :: convert long date to short date javascript 
Javascript :: how to kill all node processes in windows 
Javascript :: json stringify pretty 
Javascript :: react check if mobile or desktop 
Javascript :: enter only numbers in input field angular 
Javascript :: tailwind hover dont work 
Javascript :: npm auth0-react 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =