Angular 2 个生产 URL 在重新加载页面时中断

Angular 2 in production URLs are breaking when reloading the page

我 运行 我的应用程序正在使用 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 出现相同的错误

请任何帮助感谢您

试试这个...

index index.html;

location / {
  try_files $uri $uri/ /index.html;
}

# Location of asset folder
location ~ ^/(assets)/  {
  gzip_static on;
  gzip_types image/svg+xml text/plain text/xml text/css
    text/comma-separated-values
    text/javascript application/x-javascript
    application/atom+xml;

  expires 0;
}