官网地址:https://router.vuejs.org/zh-cn/essentials/history-mode.html
但是仅仅按照官网的做法,还是不行,看了很多人的博客和笔记才解决的。
后台需要配置很多,前端仅仅需要加上
a)
mode: "history",
b)
将webpack的配置文件的
index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: './',
改为index: path.resolve(__dirname, '../dist/index.html'),
// Paths
assetsRoot: path.resolve(__dirname, '../dist'),
assetsSubDirectory: 'static',
assetsPublicPath: '/',
这是我的参考网站:https://www.cnblogs.com/xyyt/p/7718867.html
由于后台的不熟,看了后台的代码中有下面的代码:
<error-page>
<error-code>404</error-code>
<location>/index.html</location>
</error-page>
如果对你有帮助的话,请点赞