score:1
Accepted answer
you may try this:
${window.location.search.split('=')[1]}
score:0
you can use browser native api
const query = new urlsearchparams(window.location.search);
console.log(query.get(ref))
score:0
you can use url.searchparams
const { searchparams } = new url(document.location)
code:
const { searchparams } = new url('http://localhost:3000/?ref=2926')
console.log(searchparams.get('ref'))
react component:
export const urlsearchparamvalue = ({ name }) => {
const { searchparams } = new url(document.location)
const value = searchparams.get(name)
return <span>{value}</span>
};
to use:
<urlsearchparamvalue name='ref' />
score:2
you also get value of ref from this way :
const querystring = window.location.search;
const parameters = new urlsearchparams(querystring);
const value = parameters.get('ref');
Source: stackoverflow.com
Related Query
- How to read the ref code from URL in react js
- How to read the current URL in the react application
- How to open a text file and read the contents from it on react native?
- How to read an image from the localhost url and get its width and height in javascript
- React Router with Meteor: How to remove code param from URL after redirect from OAuth without reload
- How can I get token from the URL in Nextjs / React App?
- How to read the coordinates from the event.feature.getGeometry using react and typescript?
- How to get the value from URL params in React
- How to create routes from anchor tags from react router without the # in the url
- How To Read The Code Sample At Immutable / React Document Pages
- How to delete the # from the URL when linking in react or vanilla js
- How to restrict user from accessing a particular page by typing the url using react and typescript?
- How do I get the HTTP response code from a successful React query?
- How can I turn the data that is a image came from API to url to use in img tag in react Js
- How to get the element from the ref in REACT
- How to get the reponse code from Web API in React
- In React components implemented with hooks, how can the latest component state values be read from within setInterval?
- How do I return a callback from react hooks back the parent component? like returning the list of uploaded url
- How to Extract the id from a class div in react JS such that i can assign the value of div id to a variable in my code
- how to change the address bar url from inside a react js component
- How to get data from the route url to put inside the callback function in React router?
- How to remove the hash from the url in react-router
- Making an HTML string from a React component in background, how to use the string by dangerouslySetInnerHTML in another React component
- How to get the data from React Context Consumer outside the render
- How to prevent react from re-rendering the whole component?
- How can I remove unused imports/declarations from the entire project of React Typescript?
- How to slide <View/> in and out from the bottom in React Native?
- How can I get the URL address from the browser in ReactJS (servers URL)
- How to initialize the react functional component state from props
- How to pass the match when using render in Route component from react router (v4)
More Query from same tag
- How to deploy a react js app on a No-CPanel VPS which will be using nodejs/mongodb in the backend?
- Form validation in React before data goes to back-end
- Gatsby, Environment variables not accessible in browser
- Config browserify for react templates
- Export html from draft js editor and keeping the style
- React.Component Onclick event: Comments.js:189 Uncaught TypeError: Cannot read property 'removeCommentMutation' of undefined
- Accessing the URL hostname from React JS
- How to get index of parent object when clicking on inner property?
- React-redux rerenders when creating arrays
- Why does my mock of my api return a 404 error?
- componentDidMount unexpected token error [React.js]
- use-supercluster gets empty array
- Convert String in React Components
- fullcalendar - how to render only actived resource events at agenda weekly view?
- Connect to Azure Blob Storage REST API with axios, Node.js
- Make checkbox selectable only if count is under a specific value
- How to call useMap() outside of the file where <MapContainer> is NOT called?
- How to set defalulValue or stored value in react (browser extention)
- Insert React "root" dom to be programatically on the page
- React Js getting Image from AWS s3 URL
- ReactJs adding 'active' class to a button in a list of buttons
- AJAX Cross-domain on symfony2
- 'onClick()' method isn't working properly?
- Why am I Unable to send an image from flask to react using "Send_file"
- How to customize Bootstrap variables in a React app?
- Using withRouter in context provider results in error: "Invariant failed: You should not use <Route> outside a <Router>"
- React-table filter problem with formated column data
- React JS: Filtering an array of objects by another array of objects. How to sequential execute four functions incl. several API calls
- React JS Unhandled Rejection (TypeError): item.persistVariablesLimit.trim is not a function
- react-infinite-scroll doesn't stop invoking loadmore prop function?