我是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中实现了如下所示的_714769:
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/ . 我已经找了很多关于这个问题的帖子,但我仍然可以找到解决方案 .
1 回答
你很可能错过了hashbang(
#
)试试
#/foo/apple
而不是/foo/apple
vue路由器的默认设置是使用hashbang方法 . 这依赖于使用index.html(或任何默认值为
/
url)页面,因为它之后的所有内容都不是作为url位置的一部分而是传递到应用程序中 . 例如,在一个锚<a href="index.html#first-heading">1st heading</a>
中,这将转到页面的一部分,如果您已经在该页面上,则不会重定向 .