我是 vuejs 新手。对于我的 Vuejs 应用程序,在运行“npm run build”后,我无法访问 Web 托管服务器中的“/foo/apple”等 url。它显示错误 404 我正在使用 HTML5 历史记录模式( https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations ),并且我在 dev-server.js 中实现了“connect-history-api-fallback”,如下所示:
const express = require('express')
const app = express()
app.use(require('connect-history-api-fallback')())
我的路由器/index.js
export default new Router({
mode: 'history',
{
path: '/Product',
name: 'Product',
component: Product,
},
{
path: '/Product/kraftbag',
name: 'Kraftbag',
component: Kraftbag
},
});
我的网站 http://americandunnage.n55lwi.info/ 。 我查了很多关于这个问题的帖子,但还是能找到解决方案。
最佳答案
您可能错过了 hashbang ( #
)
尝试#/foo/apple
而不是/foo/apple
vue路由器的默认设置是使用hashbang方法。这依赖于使用index.html(或任何默认为/
url)页面,因为它后面的所有内容都不会被视为url位置的一部分,而是传递到应用程序中。例如,在 anchor <a href="index.html#first-heading">1st heading</a>
中这将转到页面的一部分,如果您已经在该页面上,则不会被重定向。
关于vue.js - Vue Routes 在生产中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51391120/