直接 url 在 vuejs 中不起作用,但路由器推送有效

Direct url not working in vuejs but router push works

当我使用 this.$router.push() 加载组件 localhost:8080/scan 时,url 加载组件但是当我执行 npm run build 然后 http-server dist/ 时,url localhost:8080/scan 不起作用,给出 404。 知道为什么它在开发中工作而不是在构建之后工作。 我确实在线检查并发现这是一个 nginx 问题,但我尝试按照此文档添加 try_files $uri $uri/ /index.html;https://router.vuejs.org/en/essentials/history-mode.html 但似乎没有任何效果。非常感谢任何帮助。

请 post 问题的完整代码,或 github 存储库。否则很难猜出你的问题是什么。

如果我不得不猜测 - 你的 http-server 找不到 scan.html 因为它不存在。您有几个选择: