问题描述
我最近在生产标志-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.
推荐答案
您必须在应用程序路由文件中定义默认路由,并在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路由-生产模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!