angular - 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'}
];
可能是什么问题呢?
解决方案
我相信这必须在服务器上配置。请参考这里:https ://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml
在不知道您要部署的服务器类型的情况下,我无法具体说明。
推荐阅读
- node.js - 将csv数据直接写入节点js中的azure blob
- reactjs - 如何设置 MuiPhone 号码和 onChange 事件的值?
- python - Discord.py- ping 时如何将 bot 消息设置为服务器前缀?
- amazon-web-services - AWS S3 中的最后修改日期错误
- javascript - 如何在滚动时仅滚动鼠标指针内容?
- python - 如何将每行的列表元素插入 Python DataFrame
- javascript - 通过 DOM 更改(覆盖)多个段落元素的文本
- android - 应用程序空闲时的android网络问题
- excel - 如何通过循环遍历excel中的列表来总结过去3个月?
- api - 我怎样才能找到总余额?(股权价值)