【发布时间】:2020-12-18 19:13:26
【问题描述】:
我有 Angular 7.2 并使用 "useHash": false 并添加到 src .htaccess 文件中。在本地“npm start”上启动我的应用程序并在 localhost:4200 工作中运行。如果我导航到 localhost:4200/my-view 我会看到我的视图,但 如果重新加载页面(F5 浏览器重新加载)我会看到 404。 有什么想法吗?
【问题讨论】:
我有 Angular 7.2 并使用 "useHash": false 并添加到 src .htaccess 文件中。在本地“npm start”上启动我的应用程序并在 localhost:4200 工作中运行。如果我导航到 localhost:4200/my-view 我会看到我的视图,但 如果重新加载页面(F5 浏览器重新加载)我会看到 404。 有什么想法吗?
【问题讨论】:
问题是 proxy.conf.json
{
"/": {
"target": "http://localhost:8080/api",
"source": false
}
}
我更改代码并工作
{
"/api": {
"target": "http://localhost:8080/",
"source": false
}
}
【讨论】:
.htaccess 文件
<IfModule mod_rewrite.c>
RewriteEngine On
# -- REDIRECTION to https (optional):
# If you need this, uncomment the next two commands
# RewriteCond %{HTTPS} !on
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
# --
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
关于构建/服务
ng serve/build --base-href
【讨论】: