Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电子应用程序。多个html文件_Javascript_Node.js_Electron - Fatal编程技术网

Javascript 电子应用程序。多个html文件

Javascript 电子应用程序。多个html文件,javascript,node.js,electron,Javascript,Node.js,Electron,我有一个电子应用程序,根目录中有多个html文件 index.html 页面1.html page.html 一旦启动,我找不到从index.html重定向到page1.html的方法 有人知道怎么做吗?当您的第一个页面是index.html时,您可以在创建窗口时调用该页面 const win = new BrowserWindow(options); win.loadUrl(`file://${__dirname}/index.html`); 如果你想加载另一个页面,也许 win.loa

我有一个电子应用程序,根目录中有多个html文件

  • index.html
  • 页面1.html
  • page.html
一旦启动,我找不到从index.html重定向到page1.html的方法


有人知道怎么做吗?

当您的第一个页面是index.html时,您可以在创建窗口时调用该页面

const win = new BrowserWindow(options);
win.loadUrl(`file://${__dirname}/index.html`);
如果你想加载另一个页面,也许

win.loadUrl(`file://${__dirname}/page.html`);
我可以帮你

如果页面应在用户操作后加载(例如,单击链接)。您可以将该链接添加到index.hmtl页面。Electron在这里的工作方式与浏览器完全相同

<a href="page.html">Go to page</a>


有时人们会做一些愚蠢的事情,比如忘记一点逗号或分号。这就是其中之一。很抱歉打扰你,我用了一个链接,就像你上一个例子一样,我有一个问题。在新窗口中,我不能使用带有require('packagename');;的任何包;。它说需求没有定义。我相信这是一个解决办法。我建议使用JavaScript库进行路由,比如backbone.js或knockout.js,使用win.loadUrl(
page2.html
)加载第二个url;正在导致浏览器窗口在加载第二个页面时闪烁白色屏幕,是否有办法避免?显然,
win.loadFile(“page.html”)
win.loadUrl(`file://${remote.app.getAppPath()}/page.html`)都不起作用,但您的确实起作用。