【发布时间】:2017-11-11 08:27:35
【问题描述】:
当我加载应用程序并重定向到另一个路由时,我正在使用 Nginx 服务器在生产中运行我的应用程序,它工作正常,但是当我重新加载页面时,我收到 404 Not Found 错误。
考虑如果我在www.example.com 加载应用程序,那么在重新加载页面后路由也可以正常工作。
如果我首先重定向到另一条路由 www.example.com/about,则页面正在加载,但如果我在相同状态下重新加载页面,则会收到错误 404 Not Found。
我找到了相同的解决方案
import {bootstrap} from 'angular2/platform/browser';
import {provide} from 'angular2/core';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';
import {MyApp} from './myapp';
bootstrap(MyApp, [
ROUTER_PROVIDERS,
{provide: LocationStrategy, useClass: HashLocationStrategy}
]);
上述解决方案工作正常,但问题是我正在获取带有 # 的 URL
www.example.com/#
www.example.com/#/about
但我的要求是我不想在 URL 中出现#
即使我在 Nginx .config 文件中进行了更改,如下所示
location /subfolder/myapp/ {
try_files $uri /subfolder/myapp/index.html;
}
但 URL 仍然出现相同的错误
请大家帮忙,谢谢
【问题讨论】:
-
我认为this topic 可能会对您有所帮助。很抱歉没有在这方面提供更大的帮助。
-
@nvkfr 我尝试了此链接中给出的解决方案,但它的 HashLocationStrategy 在链接 www.example.com/#/about 中给出了 # 这是我的问题。
标签: javascript angular typescript build angular-routing