【问题标题】:ng build dist folder not rendering siteng build dist 文件夹不呈现站点
【发布时间】:2016-11-24 05:49:52
【问题描述】:

我在使我的 angular2 应用程序在 ftp 服务器上运行时遇到问题。这是我第一次将 angular2 站点添加到 ftp 服务器。我在项目文件夹中运行 ng build 并将 dist 文件夹放在 ftp 服务器上,但我得到的只是消息 Loading... from index.html Loading... 运行 ng build 后是否还有我遗漏的步骤.我在 console 中也遇到以下错误

它说丢失的文件位于 dist 文件夹中,所以我不确定为什么会出现该错误。我已经坚持了几天了,所以非常感谢任何帮助。

【问题讨论】:

    标签: angular


    【解决方案1】:

    您必须将服务器配置为从索引文件提供服务。

    所以您想将您的生产版本部署到 Apache2 服务器?然后你会注意到

    重新加载页面,除了root,还有深度链接会导致404错误 (除非您使用 HashLocation 策略)。原因是 所有 Angular2 路由都应该通过 index.html 文件提供。

    这可以通过添加一个 .htaccess 文件来实现(在同一目录中) index.html 所在的位置)具有以下内容。

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index\.html$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.html [L]
    </IfModule>
    

    查看this了解更多信息。

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2018-01-02
      • 2017-11-12
      • 2018-05-10
      • 2016-07-15
      • 1970-01-01
      相关资源
      最近更新 更多