1

I have a project: https://github.com/merrymaker14/vuegl

I decided to upload to GitHub Pages: https://merrymaker14.github.io/vuegl

But he does not go through the pages normally, although he seems to have set everything up. Why? I did everything according to the official documentation.

nuxt.config.js:


/* nuxt.config.js */
// only add `router.base = '/<repository-name>/'` if `DEPLOY_ENV` is `GH_PAGES`
const routerBase = process.env.DEPLOY_ENV === 'GH_PAGES' ? {
  router: {
    base: '/vuegl/'
  }
} : {}

export default {
  mode: 'universal',

  /*
  ** Headers of the page
  */
  head: {
    title: pkg.name,
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'description', name: 'description', content: pkg.description }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
  },

  /*
  ** Customize the progress-bar color
  */
  loading: { color: '#fff' },

  ...routerBase,

  router: {
     middleware: 'pages',
     //base: '/examples/vuegl/'
  },

  /*
  ** Global CSS
  */
  css: [
  ],

  /*
  ** Plugins to load before mounting the App
  */
  plugins: [
  ],

  /*
  ** Nuxt.js modules
  */
  modules: [
  ],

  /*
  ** Build configuration
  */
  build: {
    /*
    ** You can extend webpack config here
    */
    extend(config, ctx) {
    }
  }
}```
4
  • it dont seem that your router base is set. Did u set it during build time? Commented Apr 11, 2019 at 14:53
  • No. By the way, animation component (there's Three.js) also doesn't work. Commented Apr 11, 2019 at 15:14
  • i.sstatic.net/FX9Lw.png - that's weird. Commented Apr 11, 2019 at 15:41
  • i.sstatic.net/rehEt.png Commented Apr 11, 2019 at 15:59

1 Answer 1

6

I was running into the same problem, here's what I did to solve it.

  1. Add to nuxt.config.js:
  // Allows page refresh to work on github pages
  generate: {
    fallback: "404.html"
  },
  1. Add a blank file .nojekyll to the static/ directory (prevents github building it as a Jekyll site)

  2. When deploying you will need to do gh-pages -d dist -t true (as the default deployment ignores files starting with '.')

Why this works

There's several problems that the above solution solves.

  1. adding fallback: "404.html", this allows SPA's (single page applications) to work on Github Pages.

    1. Any route like example.github.io/my-nuxt-app/some/page will redirect to the custom 404.html file, which will keep the SPA loaded. more info here
  2. .nojekyll prevents github building it as a Jekyll site, Github automatically thinks a gh-pages site is a Jekyll site if it has a /pages directory

  3. gh-pages -d dist -t true is required so that the .nojekyll file is actually deployed to Github Pages, as by default the gh-pages command ignores files starting with .

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, Ben! Thank you. Could you explain why it works? It helped me in the same situation. I don't think .nojekyll is the main problem?
Added some more explanation, there's actually 3 problems that this solution solves...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.