javascript - 将本地网络应用程序包含到 native webview 中

标签 javascript css webview react-native single-page-application

在我的 react-native 应用程序中,我想显示一个 webview,它加载本地 html5 web 应用程序(单页应用程序,SPA)。

我能够加载一个 html 文件,它位于相对文件夹 webapp 中,使用

var webapp = require('./webapp/index.html');

<WebView source={webapp}></WebView>

正如我在本帖中所述:react native webview load from device local file system

不幸的是,这个本地网络应用程序的 Assets ,如 .js 和 .css 文件,没有被网络应用程序加载。

在 react-native 应用程序的开发过程中,这些文件可通过开发服务器获得。但是,当应用程序在 iOS 设备上打包并运行时, Assets 不可用(我在 Safari 开发人员工具中收到 404 错误)。

我如何确保 webapp 文件夹中的所有 Assets (JS、CSS 等)在本地打包的应用程序中可用。

最佳答案

By setting the baseURL, the WebView knows where to look for the css/js that you link to

喜欢:

<WebView baseURL="/webApp" html={html} />

在github上查看问题的答案:

https://github.com/facebook/react-native/issues/1442#issuecomment-106906969

或阅读 nick-weaver 详细回答的示例: Loading javascript into a UIWebView from resources

关于javascript - 将本地网络应用程序包含到 native webview 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35851788/

相关文章:

javascript - 在 jQuery 中检索 click() 处理程序供以后使用

javascript - 混搭 : Select Box/Disabled Input/Getting Info From Database

javascript - Jquery .text() 与 php foreach

CSS 框阴影不起作用

html - 将部分的边缘隐藏在其他部分后面

android - 如何在android的WebView中设置文本大小

javascript - 如何通过javascript打开默认日期选择器?

使用默认运算符的 Javascript 引用错误

javascript - 我应该如何在不向用户显示的情况下使用 Electron 呈现网页?

php - Wordpress 标题损坏