Angular 4 路由 --prod 模式 [英] Angular 4 routing --prod mode
问题描述
我最近在生产标志 --prod
中使用 angular 4 构建了一个应用程序.
I've recently built an app using angular 4 in production flag --prod
.
它在 dist 文件夹中给了我一些静态文件,之后我将 dist 文件上传到 AWS S3 存储桶中.一切顺利,直到我点击刷新.在/page1 或/page2 等其他路由上单击刷新时,它显示404 未找到"没有此类关键错误.
It gave me some static files in the dist folder and after that I've uploaded the dist files in AWS S3 bucket. It all went fine until I clicked refresh. While clicking refresh on other routes like /page1 or /page2 it is showing '404 not found' no such key error.
我在这里做错了什么吗?我知道问题存在是因为 dist 文件夹中只有一个文件 (index.html).但是其他路线呢?
Am I doing anything wrong here? I know the problem exists because there is only one file (index.html) in the dist folder. But what about other routes?
如何在刷新页面后使其他页面可用.
How could I make other pages available even after refreshing the page.
推荐答案
你必须在你的 app-route 文件中定义默认路由,并像这样在 RouterModule 中添加第二个参数
You have to do define default routing in your app-route file and add the second parameter in RouterModule like that
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
它对我有用
这篇关于Angular 4 路由 --prod 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!