首页 > 解决方案 > 前端/后端路由配置

问题描述

$ tree .
.
├── main.go
└── static
    └── output_of_npm_run_build

我使用 vue.js 和 vue 路由器作为前端,使用 golang 作为后端。我试图完成的事情:

如果我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.jsgovue-router

解决方案


您需要更新托管配置。以前在使用 React、Vue 等前端 JS 框架时都会出现这个问题。

因此,如果您example.com/about在地址栏上手动输入,页面将显示“404 Not Found”。

我推荐这个答案来解决你的问题。

Vue路由器不适用于nginx


推荐阅读