i18n icon indicating copy to clipboard operation
i18n copied to clipboard

nuxt generate won't generate index.html with prefix strategy

Open steffenstolze opened this issue 7 months ago • 7 comments

Environment

  • Operating System: Darwin
  • Node Version: v20.15.0
  • Nuxt Version: ^3.12.3
  • CLI Version: 3.12.0
  • Nitro Version: -
  • Package Manager: npm
  • Builder: -
  • User Config: devtools, ssr, nitro, experimental, modules, i18n
  • Runtime Modules: @nuxtjs/i18n@^8.3.1
  • Build Modules: -

Reproduction

https://github.com/steffenstolze/nuxt_i18n_bug

Describe the bug

Running nuxt generate should create an index.html file in the .output/public folder when using strategy: 'prefix' in the i18n config. If this file is missing, you get a 404 when accessing root, since every route is prefixed with the locale code.

With the latest Nuxt and Nuxt i18n versions, it doesn't:

"dependencies": {
    "@nuxtjs/i18n": "8.3.1",
    "nuxt": "3.12.3"
}
image

With older ones it works up to these versions:

"dependencies": {
    "@nuxtjs/i18n": "8.3.0",
    "nuxt": "3.11.2"
}
image

From here on, if you bump up @nuxtjs/i18n to 8.3.1 or nuxt to 3.12.0 and higher, the index.html is not created anymore.

Additional context

As a workaround I added the following to the nitro config, to generate the index.html manually once the 200.html file is created.

While this works, it also feels super hacky and shouldn't be needed.

	nitro: {
		static: true,
		// Hacky approach to redirect create index.html file for root redirect
		hooks: {
			'prerender:generate'(route, nitro) {
				if (route?.route === '/200.html') {
					const redirectHtml =
						'<!DOCTYPE html><html><head><meta http-equiv="refresh" content="0; url=/de"></head></html>';
					const outputPath = path.join(
						nitro.options.output.publicDir,
						'index.html'
					);
					writeFileSync(outputPath, redirectHtml);
				}
			},
		},
	},

Logs

No response

steffenstolze avatar Jul 05 '24 16:07 steffenstolze