Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.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
Ng build Angular 2 Cli应用程序404硬刷新时出错_Ng Build - Fatal编程技术网

Ng build Angular 2 Cli应用程序404硬刷新时出错

Ng build Angular 2 Cli应用程序404硬刷新时出错,ng-build,Ng Build,使用ng build构建时,构建成功,可以访问应用程序 但是,当在生产模式中使用以下命令时: ng build --prod 这给了我一个错误: “TypeError:无法将未定义或null转换为对象” 为apache2添加.htaccess文件并在文件中插入代码 RewriteEngine on # Don't rewrite files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_

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

但是,当在生产模式中使用以下命令时:

ng build --prod
这给了我一个错误:

“TypeError:无法将未定义或null转换为对象”


为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文件change base href

index.html

<base href="/angular/">

这里是目录

然后打开/etc/apache2/sites enabled/000-default.conf文件,并在
标记上添加以下规则

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

允许超越所有