Sam85
Sam85

Reputation: 179

Running Nuxt3 on a specific path only

I struggle to get my app working with static deployment with Nuxt. I would like to deploy the static files to "test" subdirectory of my website (www.example.com/test).

When I run "npm run generate", it generates a ".output/public" directory with files I copy to the "test" folder of my production server. But I get 404 errors when doing that: my index.html file in the public folder references files in the root folder of my website (extract):

<meta name="head:count" content="2">
<link rel="modulepreload" href="/_payload.js">
<link rel="modulepreload" as="script" crossorigin href="/_nuxt/entry.8af327a9.js">

As you can see, the page is looking for js files in the root directory instead of /test directory.

Here is my nuxt.config.ts with router config:

export default defineNuxtConfig({
    target: 'static',
    css: [
        '~/assets/global.scss'
    ],
    router: {
        base: '/test/'
    }
})

I tried also to set up public_path to "/test" but it does not work either. Is there something I misunderstood?

Upvotes: 1

Views: 3085

Answers (1)

some-user
some-user

Reputation: 4894

You should set the base URL in nuxt.config.js|ts:

export default defineNuxtConfig({
  app: {
    baseURL: '/test/'
  }
})

See: https://v3.nuxtjs.org/api/configuration/nuxt.config#baseurl

Upvotes: 2

Related Questions