我已经使用路由53部署了一个带有S3和云锋的VueJS应用程序.看起来一切都很顺利.我可以在https://my-domain.com点访问该网站,并且可以导航到使用Vue router设置的不同路由.然而,当我试图直接访问https://my-domain.com/about时,我看到以下错误:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<link type="text/css" id="dark-mode" rel="stylesheet" href=""/>
<style type="text/css" id="dark-mode-custom-style"/>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>about</Key>
<RequestId>8371CJFJ48JM68239</RequestId>
<HostId>
/fQp7V6SuN0eDPgZpTroQrrxmfVQJTjXtroij56OIJONB56048OIaZDa4snkjc/Ygr/oZu0=
</HostId>
</Error>

以下是我的AWS资源的设置:

S3桶

属性

所有属性都被禁用(我没有静态网站托管设置,因为我使用的是https)

权限(公共)

Public Access Settings

所有四个选项都设置为false

Access Control List

公共访问:每个人都可以读取和列出对象

桶政策

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "PublicReadForGetBucketObjects",
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::mybucketname.com/*"
        }
    ]
}

CORS配置

这里什么都没有

路由53

我有一个域名,它有一个托管区域,有5条记录:

  • mydomain.com:创纪录;指向云锋分布的点

  • 默认的NS条和SOA条我没有更改的记录

  • *.mydomain.com:创纪录;也可以指向前端子域的云锋分布

  • api.mydomain.com:创纪录;指向后端API服务的ALB

云锋

以下是我的云锋发行版的General个设置:

Distribution ID: 12356OIJSGSU9I
ARN: arn:aws:cloudfront::123456789012:distribution/ABCD1234
Log Prefix: -
Delivery Method: Web
Cookie Logging: Off
Distribution Status: Deployed
Comment: -
Price Class: Use All Edge Locations (Best Performance)
AWS WAF Web ACL: -
State: Enabled
Alternate Domain Names (CNAMEs):
*.mydomain.com
mydomain.com
SSL Certificate: mydomain.com (abc1234-1234-1234-1234-abcd1234)
Domain Name: abcd1234.cloudfront.net
Custom SSL Client Support: Only Clients that Support Server Name Indication (SNI)
Security Policy: TLSv1.1_2016
Supported HTTP Versions: HTTP/2, HTTP/1.1, HTTP/1.0
IPv6: Enabled
Default Root Object: index.html
Last Modified: 2019-02-19 11:45 UTC-5
Log Bucket: -

我没有设立任何来源地小组.我不确定我是否需要这个,但听起来它可以帮助解决这个问题.

我也听说过AWS Amplify(https://console.aws.amazon.com/amplify/).

我可以更改哪些设置,以便将对域的非root请求路由到VueJS应用程序?

推荐答案

这是SPA的一个典型问题,因为像/dashboard条这样的路由不是服务器上真正的物理路由.要解决此问题,只需打开CloudFront发行版,转到"错误页面"选项卡,并使用以下设置创建自定义错误响应:

enter image description here

这实际上是告诉CloudFront忽略404错误,只返回HTTP 200响应,并指向/index.html.您的SPA将通过Vue路由在内部处理任何"未找到页面"错误.This美元可能会有所帮助.

Vue.js相关问答推荐

将 v-calendar 与以时间和日期格式出现的事件一起使用

VueJS:如何在组件数据属性中引用 this.$store

aspnet core如何在deploy上构建webpack

如何在 Vuetify v-data-table 上对齐标题

错误:您可能需要额外的加载器来处理这些加载器的结果.

POST 文件连同表单数据 Vue + axios

使用 VueJS 在 v-for 中转换

即使在客户端设置 Access-Control-Allow-Origin 或其他 Access-Control-Allow-* 标头后也出现 CORS 错误

使用vue.js单击时如何获取按钮的值

动态注册本地 Vue.js 组件

[Vue 警告]:无效的props:propsscrollThreshold的类型判断失败.期望的数字,得到字符串

Vuejs css 范围性能

Vue在按钮单击时添加一个组件

Vuejs - 使用 v-if 切换的保持活动组件

如何从方法内部访问数据

在 Vuejs 中放置 firebase.auth().onAuthStateChanged() 的位置

TypeError: Object(...) 不是 Vue 中的函数

如何使用vue js判断组件本身的数据何时发生变化?

如何将单选按钮绑定到 vuex store ?

Vue-meta:metaInfo 无权访问计算(computed)属性