Run NUXT without server

512 views Asked by At

How can I run a static NUXT project without a server?

That's what I did:

  1. I created a new project (without any line of code) with VUETIFY

  2. I ran the command npn run generate

  3. I went to dist/index.html

  4. The project opens but no link is clicked

  5. I added the line in nuxt.config.js

    route: { base: '/ProjectName/' },

  6. I ran generate again

  7. The links are still not clicked, And if there is a clicked link it points to drive c

1

There are 1 answers

0
wulf11 On

Try to switch to hash mode in your router! (https://v2.nuxt.com/docs/configuration-glossary/configuration-router/#mode)

In your nuxt.config.js it should look like this:

  // Target: https://go.nuxtjs.dev/config-target
  target: 'static',

  ssr: false, // Disable Server Side rendering

  router:
  {
    mode: 'hash', // switch from history mode, that requires a server to fake filesystem calls, to totally client based approach where all urls prefixed with #.
    base: './', // change to './' if you want to test it locally
  },

Now you should be able to use "npm run generate" and just open the index.html file in your "dist" directory.