Angular 4路由

编程入门 行业动态 更新时间:2024-10-18 06:13:32
本文介绍了Angular 4路由-生产模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我最近在生产标志-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路由

本文发布于:2023-10-31 13:20:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546203.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!