【问题标题】:Vue Website Returns "Cannot Get /path" On All Pages EXCEPT IndexVue 网站在除索引之外的所有页面上都返回“无法获取 /path”
【发布时间】:2019-12-05 19:45:48
【问题描述】:

我在 Node.js 上使用 Vue 在 AWS EC2 实例上托管我的网站。我没有索引 node.js 文件,只有 vue-router 文件。我使用 AWS CloudFront 将我的证书绑定到我的流量。问题是每次我通过服务器的链接访问该站点时,该站点都可以正常运行,但是每当我通过云前端链接访问它时,只会显示该网站的索引。没有 /about 或 /contact;相反,它返回Cannot GET /about。

我的路由器:

import Vue from 'vue';
import Router from 'vue-router';
import VueCookies from 'vue-cookies';
import Home from './views/Home.vue';
import NotFound from './views/NotFound.vue';


Vue.use(Router);
Vue.use(VueCookies);

VueCookies.config('7d');
VueCookies.set('theme', 'default');
VueCookies.set('unique', Date.now());
VueCookies.set('rwapi-uuid', `v3-${Date.now()}-x9k0`)

export default new Router({
  mode: 'history',
  routes: [
    { path: '/', name: 'INDEX', component: Home },
    { path: '/about/', name: 'ABOUT', component() { return import('./views/About.vue'); } },
    { path: '/portfolio', name: 'PORTFOLIO', component() { return import('./views/Port.vue'); } },
    { path: '/contact', name: 'CONTACT', component() { return import('./views/Contact.vue'); } },
    { path: '/login', name: 'LOGIN', component() { return import('./views/Login.vue'); } },
    { path: '/404', component: NotFound },
    { path: '*', redirect: '/404' },
  ],
});

我已经尝试将 historyApiFallback: true 添加到我的 webpack 配置中,但没有效果。

【问题讨论】:

    标签: node.js vue.js amazon-ec2 amazon-cloudfront vue-router


    【解决方案1】:

    根据Vue Router 的文档,在history 模式下使用路由器时,您的网络服务器需要additional configuration

    我不完全知道 EC2 实例是如何工作的,但如果您没有将所有请求代理到 index.html 的网络服务器,Vue-router 将无法处理其他请求。

    【讨论】:

    • 谢谢,我会尝试使用 node 来重定向请求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2018-01-13
    • 1970-01-01
    • 2016-07-26
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多