React Native - Parse URL to get request variable
There are ways to do this that you can use from the JS ecosystem. Try URI.js https://github.com/medialize/URI.js
source to share
This should do the trick
var url = "http://example.com?myVar=test&otherVariable=someData&number=123"
var regex = /[?&]([^=#]+)=([^&#]*)/g,
params = {},
match;
while (match = regex.exec(url)) {
params[match[1]] = match[2];
}
console.log(params)
source to share
Try url https://www.npmjs.com/package/url
"This module has url resolution and parsing utilities to enforce function parity using the node.js core url module."
The URL node object is available to your app when using the responsive Chrome debugger, but not available on your iPhone when not tied.
So use this package
npm install url
Sample code:
import url from 'url';
...
let urlObject = url.parse(inUrlString);
let outUrlString = urlObject.protocol + '//' + urlObject.host + '/more/jump?jump_path=' + encodeURIComponent(urlObject.pathname);
source to share
Update. This is not a solution to the above question because it doesn't work unless in debug mode. However, I did not delete this answer because I think it points to a note worthy of a nuance.
JavaScript very native URL Web API is supported in React Native (using version 0.46). You can use to parse or assemble any part of the URL with great ease.
The API is identical to the WHATWG API URL Module API in Node.js This answer should be more obvious, but easy to get lost with the number of URL parsing packages available.
Edit: This only works in JS debug mode for some reason, not otherwise. So this solution is really not valid, but I am leaving it here because I would like to know how to get the same url module as to work with native-native.
source to share