【问题标题】:Angular 2 Cli application 404 Error on hard refreshAngular 2 Cli 应用程序 404 硬刷新时出错
【发布时间】:2018-11-07 01:34:26
【问题描述】:

使用ng build构建时,构建成功,可以访问应用。

但是,在生产模式下使用:

ng build --prod

它给了我一个错误:

“TypeError:无法将 undefined 或 null 转换为对象”。

【问题讨论】:

    标签: ng-build


    【解决方案1】:

    为apache2添加.htaccess文件并在文件中插入代码

    RewriteEngine on
    # Don't rewrite files or directories
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    # Rewrite everything else to index.html to allow html5 state links
    RewriteRule ^ index.html [L]
    

    和 index.html 文件更改 base href

    index.html

    <base href="/angular/">
    

    这里的角度是目录。

    之后打开 /etc/apache2/sites-enabled/000-default.conf 文件并在 &lt;VirtualHost&gt; 标签上添加以下规则

    <Directory "/var/www/html">
       AllowOverride All
    </Directory>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-20
      • 1970-01-01
      • 2014-11-25
      • 2017-11-29
      • 2015-08-02
      • 2015-06-22
      • 2017-08-09
      • 1970-01-01
      相关资源
      最近更新 更多