【问题标题】:Failed to load resource: net::ERR_FILE_NOT_FOUND in angular无法加载资源:net::ERR_FILE_NOT_FOUND 角度
【发布时间】:2018-11-07 15:24:02
【问题描述】:

我使用电子构建我的应用程序,这些错误发生在 chrome 控制台中。否则,如果我通过 ng serve 运行它,我的应用程序运行良好。错误如下:

Failed to load resource: net::ERR_FILE_NOT_FOUND
polyfills.bundle.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
styles.bundle.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
vendor.bundle.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
main.bundle.js:1 Failed to load resource: net::ERR_FILE_NOT_FOUND
/C:/favicon.ico:1 Failed to load resource: net::ERR_FILE_NOT_FOUND

我在 dist 文件夹中的 index.html 文件是:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>IMS</title>
   <base href="/"> 

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="styles.50e334ed602d9817f7d7.bundle.css" rel="stylesheet"/></head>
<body>

 <app-root>Loading...</app-root>

<script type="text/javascript" src="inline.9c6676de3e2948b5be6b.bundle.js"></script><script type="text/javascript" src="polyfills.e19c18e1070c8c3aa743.bundle.js"></script><script type="text/javascript" src="vendor.e2a9b8f51e6c245f32be.bundle.js"></script><script type="text/javascript" src="main.eb7ca8d005a358b399e4.bundle.js"></script></body>
</html>

我在 src 文件夹中的 index.html 文件的代码是:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>IMS</title>
   <base href="./"> 

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>

 <app-root>Loading...</app-root>

</body>
</html>

【问题讨论】:

    标签: javascript html angular electron desktop-application


    【解决方案1】:

    https://angular.io/docs/ts/latest/guide/router.html

    &lt;head&gt; 标记之后添加基本元素。如果app 文件夹是应用程序根目录,就像我们的应用程序一样,请设置href准确,如下所示。

    &lt;base href="/"&gt; 告诉 Angular 路由器 URL 的静态部分是什么。然后路由器只修改 URL 的剩余部分。 在 src/index.html 中将 Base href 设置为 '/'

    <base href="/"> 
    

    你可以了解更多关于base hrefhere

    【讨论】:

    • 这对我不起作用,应用程序与 ng serve 命令正常工作。但是当我为电子构建时,它没有加载文件,因为文件是在构建后从 dist 文件夹加载的。
    • 我将它设置为 &lt;base href="./"&gt; 这对我有用
    【解决方案2】:

    对我来说,这对 ng serveng build 都很好:

    <base href="">
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2017-12-24
      • 1970-01-01
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多