首页 > 解决方案 > Angular 6 - 在生产中部署应用程序

问题描述

我正在尝试将我的第一个 Angular 应用程序上传到生产环境,我已经执行了命令:

ng build --prod --build-optimizer

接下来我复制了 server 文件夹根目录下 dist 文件夹的内容。

我正确地看到了应用程序,唯一的问题是当我在浏览器中重新加载页面时,它给了我以下错误:

Not Found
The requested document was not found on this server.

在 index.html 文件中,我以这种方式拥有基本标记:

<base href = "/">

这是我的路线文件:

const routes: Routes = [
  { path: '', redirectTo: '/home', pathMatch: 'full' },
  { path: 'home', component: HomeComponent },
  { path: 'writer', component: WriterComponent },
  { path: 'music', component: MusicComponent },
  { path: '404', component: NotFoundComponent},
  { path: '**', redirectTo: '/404'}
];

可能是什么问题呢?

标签: angulardeployment

解决方案


我相信这必须在服务器上配置。请参考这里:https ://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml

在不知道您要部署的服务器类型的情况下,我无法具体说明。


推荐阅读