【问题标题】:Using connect-history-api-fallback' ,but not sure how to implement in vuejs使用 connect-history-api-fallback' ,但不确定如何在 vuejs 中实现
【发布时间】:2020-06-23 07:02:58
【问题描述】:
当我在 vuejs 中刷新页面时,我收到 nginx 错误,因为我正在使用 connect-history-api-fallback',但不确定如何在 vuejs 中实现,我看到它在 app.js 中的使用与中间件服务器,我们如何在vuejs的独立应用中使用
【问题讨论】:
标签:
vue.js
nginx
npm
vuejs2
【解决方案1】:
我认为你可以通过两种方式做到这一点。
-
只有 nginx(nginx 配置)(完整的 nginx 配置检查this link)
location / {
try_files $uri $uri/ /index.html;
}
-
使用类似服务器的 express(带有连接历史记录 api-fallback 的 server.js 文件)
const express = require('express');
const history = require('connect-history-api-fallback');const app = express();
app.use(history());
app.use(express.static('src'));app.get('/', (req, res) => {
res.sendFile('src/index.html');
});app.listen(3000, () => console.log('server started'));
--在您的路由器中,您需要使用历史模式,请遵循此vuejs history mode。
关注此博客以供参考https://medium.com/swlh/using-vue-routers-history-mode-6d9395e8122e