Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hybrid rendering doesn't generate spa fallback html #23055

Open
a1mersnow opened this issue Sep 7, 2023 · 5 comments
Open

Hybrid rendering doesn't generate spa fallback html #23055

a1mersnow opened this issue Sep 7, 2023 · 5 comments

Comments

@a1mersnow
Copy link

a1mersnow commented Sep 7, 2023

Environment

  • Operating System: Darwin
  • Node Version: v16.20.1
  • Nuxt Version: 3.6.5
  • Nitro Version: 2.5.2
  • Package Manager: pnpm@8.7.4
  • Builder: vite
  • User Config: nitro, app, ui, devtools, typescript, vue, modules, content, colorMode, vite
  • Runtime Modules: @nuxt/content@2.7.2, @nuxthq/ui@2.7.0-28233674.a2970cb
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/github-h3ry36?file=nuxt.config.ts

Describe the bug

Got this config:

export default defineNuxtConfig({
  nitro: {
    routeRules: {
      '/**': { prerender: true },
      '/spa': { ssr: false },
    },
    prerender: {
      crawlLinks: true,
      routes: ['/', ],
    },
  },
})
image After `pnpm build`, there are no fallback html generated for `spa` page.

If this isn't a bug, how to generate the fallback htmls like nuxt generate?

Additional context

No response

Logs

No response

@stackblitz
Copy link

stackblitz bot commented Sep 7, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@jf908
Copy link

jf908 commented Oct 26, 2023

I was having a similar problem but I think I found the solution in the docs.

The spa fallback page is called 200.html.

I turned prerendering off by default via routeRules but this meant that 200.html wasn't being generated. I solved this by adding it to my route rules:

export default defineNuxtConfig({
  routeRules: {
    '/200.html': { prerender: true },
    '/**': { prerender: false },
  },
});

Then I configured my back-end to use 200.html as the fallback page and everything worked.

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
@a1mersnow
Copy link
Author

a1mersnow commented Oct 27, 2023

@jf908 It works!

However, I didn't turn prerendering off by default, but I still need to declare /200.html to make it work:

nitro: {
  routeRules: {
    '/200.html': { prerender: true },
    '/**': { prerender: true },
    '/mine/**': { ssr: false },
    '/shop/**': { ssr: false },
  },
  prerender: {
    crawlLinks: true,
    routes: ['/'],
  },
},

Without your solution, I worked around it previously by using nuxt generate && rm -rf /mine/**/*.html /shop/**/*.html because it will generate 200.html and 404.html(Although I don't known how to use 404.html with nginx. I will appreciate if you can tell me how.).

With your solution, I can get back to the normal nuxt build~

However, I think this should be explicitly documented in docs. @danielroe

@danielroe
Copy link
Member

Yes, it would make sense to make sure we explain about 200.html and 404.html and how to generate them.

@zoellner
Copy link

Depending on the preset (I am using aws-lambda) it seems that the configuration needs to be slightly different from what is reported here.

What works for me is

export default defineNuxtConfig({
  nitro: {
    prerender: {
      routes: ['/200/index.html'],
    },
    routeRules: {
      '/200/index.html': { ssr: false },
    }
  }
});

@danielroe danielroe removed the 3.x label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants