我已经在christopherkade.github.io的主分支中部署了/dist文件夹的内容,它成功地部署了website文件夹.

但当我使用导航栏(christopherkade.com/postschristopherkade.com/work)导航并重新加载页面时,Github页面会出现一个错误:

404找不到文件

请注意,我的路由是使用Vue路由完成的,如下所示:

export default new Router({
  mode: 'history',
  routes: [    
    {
      path: '/',
      name: 'Home',
      component: Home
    },
    {
      path: '/work',
      name: 'Work',
      component: Work
    },
    {
      path: '/posts',
      name: 'Posts',
      component: Posts
    },
    { path: '*', component: Home }
  ]
})

我的项目是这样构建的:

build: {
    // Template for index.html
    index: path.resolve(__dirname, '../docs/index.html'),

    // Paths
    assetsRoot: path.resolve(__dirname, '../docs'),
    assetsSubDirectory: 'static',
    assetsPublicPath: '/',

    /**
     * Source Maps
     */

    productionSourceMap: true,
    // https://webpack.js.org/configuration/devtool/#production
    devtool: '#source-map',

    // Gzip off by default as many popular static hosts such as
    // Surge or Netlify already gzip all static assets for you.
    // Before setting to `true`, make sure to:
    // npm install --save-dev compression-webpack-plugin
    productionGzip: false,
    productionGzipExtensions: ['js', 'css'],

    // Run the build command with an extra argument to
    // View the bundle analyzer report after build finishes:
    // `npm run build --report`
    // Set to `true` or `false` to always turn it on or off
    bundleAnalyzerReport: process.env.npm_config_report
  }

是什么导致了这个问题?

推荐答案

但当我使用导航栏导航时(christopherkade.com/posts或

Let me explain why 100 is being shown

当从web浏览器触发christopherkade.com/posts时,域christopherkade.com映射到的机器被联系.

在其服务器中搜索路径/posts.在您的情况下,我相信服务器中不存在/posts的路由.结果404 is displayed

There are few ways to fix this

为了防止浏览器在触发请求christopherkade.com/posts时联系服务器,您可以在路由配置中保留mode : 'hash'

How 100 works? This is one way to fix your issue

mode : 'hash'使用默认浏览器行为,即防止http请求触发#之后存在的详细信息

因此,当您触发christopherkade.com/#/posts时,浏览器将触发christopherkade.com,并且一旦收到响应,将调用来自route config/posts路由.

让我们假设你对服务器有控制权,并且你是坚定的

然后,您可以将服务器配置为每次发送任何路径时,服务器都会以相同的页面响应.一旦在浏览器中收到响应,路由将自动启动.

Even in your current program, the routeConfig gets kicked off when you click any links (like work,posts) in your page. This is because the browser behavior is not being invoked at this point.

enter image description here

In your case, you use github for hosting this app with 100我自己必须寻找一个具体的解决方案来解决这个问题.一旦我得到答案,我会更新我的答案.

我希望这是有用的.

Vue.js相关问答推荐

用于循环数组的模板元素内的条件渲染

视图中的 vue 样式不适用于 html

Vue Datepicker 不会在渲染时显示默认日期

我在表格中创建了一个包含信息的新行,但在 Cypress e2e 测试中我无法获得最后一行(新行)

如果在 VueJS/VuetifyJS 中切换switch,则调用函数

将初始值设置为可直接在 HTML 中使用的 vue.js 模型

禁用 vue-cli webpack 编码图像 base64

无法在 Vuex 中的其他操作中反跳操作

为什么在 Vue.js 中使用 `var` 关键字?

使用 vuex 更新数据

Vue.js 如何计算总数?

带有 vue.js 的 img 网址

eslint – 如何知道 defined定义规则的位置

将数据传递给另一条路由上的组件

vuejs中通过变量动态调用方法

vue-router的router-link实际刷新?

laravel vuejs/axios put request Formdata 为空

使用 vuex-persistedstate 仅使一个模块持久化

在~/components/AddPlaceModal.vue中找不到导出AddPlaceModal

使用 svelte js 的原因