简体   繁体   中英

Set path to local html in React Native Webview

I currently have a react native webview where the url is set to the path to a html file inside my workspace. In development, everything is working accordingly and the page gets rendered with the parameters set in the url.

My problem, i would like to move to production and hence the IP address used in the path to the index.html file is no longer available.

Here is my code:

const [url,setUrl]=useState(`http://IPADDRESS_ONMYCOMPUTER:19000/app/screens/Payment/index.html?sessionId=${route.params.sessionId}`)


return (
source={{uri:url}}
)

Update

I have created the html files on my server and are working accordingly when i access them from the browser. Unfortunately, they are not working inside my webview in react native.

I keep getting an error and the page doesnt load.

Here is my updated Code:

Here is my code:

const [url,setUrl]=useState(`http://SERVERIPADDRESS/api/payments/index.html?sessionId=${route.params.sessionId}`)


return (
source={{uri:url}}
)

for this you do not need to your local url. there are multiple solution to this. if you page is static you can copy the source code and use this package to render your html. if the page is dynamic you have to put that on some server and the specify that's url.

if your url is http so have to allow http request in your application.

for android add this

<application android:usesCleartextTraffic="true">
</application>

for details visit this question

for iOS visit this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM