vue.js - Vue Routes 在生产中无法正常工作

标签 vue.js server routes vuejs2 vue-router

我是 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/

相关文章:

javascript - 如何使用 Vue 实例中的全局混合方法

python - Pylons/路线 url_for() 在模板内改变了吗?

javascript - 在 Vue Webpack 中禁用转译器以更轻松地调试

javascript - Vue 将类添加到目标但从其他实例中删除

server - 如何在 Wildfly 配置文件中使用变量?

http - Crystal-lang 没有重载匹配 'HTTP::Server.new' 类型为 Int32 的 http 服务器

iphone - 在 iPhone MapView 上显示当前位置和所需位置之间的路线

Laravel 4.2 子域路由参数

javascript - vue-image-upload-resize 重置图片文件

node.js - react 应用程序 : Using Node/express as middle-end proxy server