React-native – React Native – Parse URL to get Query Variable

react-native

Looking for a way to parse a URL to get a query variable in React Native received from Linking.

I'm receiving the URL as something like:

url-app-scheme://somePage?someVar=someVal

I'd like to get the someVar value from the URL.

Any thoughts?

Best Solution

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)