I am trying to get URL params in a React Native app.
What I tried to do:
const parsedUrl = new URL(url)
// here the searchParams are empty list
console.log(parsedUrl.searchParams)
[Error: not implemented]
const parsedUrl = new URLSearchParams(url)
console.log(parsedUrl.get(param))
const getSearchParamFromURL = (url, param) => {
const include = url.includes(param)
if (!include) return null
const params = url.split(/([&,?,=])/)
const index = params.indexOf(param)
const value = params[index + 2]
return value
}
const _url = 'myapp://?code=123123-1123123-418c-33213-123123¶m_key=param_value'
getSearchParamFromURL(_url, 'code') // output: 123123-1123123-418c-33213-123123