[英]Vue Website Returns “Cannot Get /path” On All Pages EXCEPT Index
I am using Vue on Node.js to host my website on an AWS EC2 instance. 我正在Node.js上使用Vue将网站托管在AWS EC2实例上。 I dont have an index node.js file, just the vue-router file. 我没有索引node.js文件,只有vue-router文件。 I use AWS CloudFront to bind my certificate to my traffic. 我使用AWS CloudFront将证书绑定到流量。 The problem is that everytime i access the site through the server's link, the site works perfectly, but whenever i access it through the cloud-front link, only the index of the website will show up. 问题是,每次我通过服务器的链接访问该站点时,该站点均正常运行,但是每当我通过云前端的链接访问该站点时,只会显示该站点的索引。 No /about or /contact; 没有/ about或/ contact; instead it returns Cannot GET /about. 而是返回Cannot GET / about。
My Router: 我的路由器:
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' },
],
});
I have already tried to add the historyApiFallback: true
to my webpack config but it had no effect. 我已经尝试将historyApiFallback historyApiFallback: true
添加到我的webpack配置中,但是没有效果。
According to Vue Router 's documentation, when using your router in history
mode, your webserver requires additional configuration . 根据Vue Router的文档,在history
模式下使用路由器时,您的Web服务器需要其他配置 。
I don't exactly know how do EC2 instances work, but if you don't have a webserver proxying all your requests to index.html
, Vue-router will not be able to handle the other requests. 我不完全知道EC2实例如何工作,但是如果您没有网络服务器将所有请求代理到index.html
,则Vue-router将无法处理其他请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.