$ tree .
.
├── main.go
└── static
└── output_of_npm_run_build
我使用 vue.js 和 vue 路由器作为前端,使用 golang 作为后端。我试图完成的事情:example.com/api/...
example.com
, example.com/about
, example.com/login
等)example.com/post/{post_id}
对于前端和后端如果我去
example.com
并点击按钮about
, vue 路由器会显示 about
组件并将 url 更改为 example.com/about
无需与后端交谈,这是预期的。但是如果我输入 example.com/about
直接到地址栏并按回车,请求直接到后端。由于文件about
不存在,返回404。有没有办法返回
static/index.html
并以某种方式告诉 Vue 路由器渲染 xxx
组件即使 example.com/xxx
由浏览器直接发送到服务器(example.com/api
除外)?谁应该负责路由
example.com/post/{post_id}
?
最佳答案
您需要更新托管配置。以前在使用 React、Vue 等前端 JS 框架时都会出现这个问题。
所以如果你输入 example.com/about
手动在地址栏上,页面将显示“404 Not Found”。
我推荐这个答案来解决你的问题。
Vue router is not working with nginx
关于vue.js - 前端/后端路由配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62951897/