【发布时间】:2020-11-07 03:18:03
【问题描述】:
$ tree .
.
├── main.go
└── static
└── output_of_npm_run_build
我使用 vue.js 和 vue 路由器作为前端,使用 golang 作为后端。我试图完成的事情:
-
使用 golang(标准库或 gorilla/mux)来处理
example.com/api/... -
vue 路由器负责所有 vue 组件(
example.com、example.com/about、example.com/login等) -
用于前端和后端的 RESTful API
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}?
【问题讨论】:
标签: vue.js go vue-router