“String kueri di React JS” Kode Jawaban

Nilai Parameter Bereaksi Dari String Kueri

// 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), {});
Gleaming Goat

Dapatkan kueri Params Bereaksi

new URLSearchParams(this.props.location.search).get("your_query_param_key")
Testy Tarsier

String kueri di React JS

{
 Site:"gfg",
 Subject:"react"
}
Modern Macaw

Jawaban yang mirip dengan “String kueri di React JS”

Pertanyaan yang mirip dengan “String kueri di React JS”

Lebih banyak jawaban terkait untuk “String kueri di React JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya