#Unexpected behaviour in pages:extend-hook in hybrid mode

4 messages · Page 1 of 1 (latest)

knotty birchBOT
#

Hi @untold musk. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, I can offer some insights into your issue with the pages:extend hook in hybrid mode.

The behavior you're experiencing where the routes work fine with SSR disabled but return 404 errors in hybrid mode (SSR enabled) is unexpected and might be related to how Nuxt handles dynamic routes in different rendering modes.

Here are a few points to consider:

  1. The pages:extend hook is the correct way to add custom routes programmatically in Nuxt 3, as mentioned in the Custom Routing documentation (https://nuxt.com/docs/guide/recipes/custom-routing#nuxt-module).

  2. However, there might be an issue with how these dynamically added routes are being processed in SSR mode. This could be related to the way Nuxt augments pages with metadata before and after the pages:extend hook, as mentioned in a GitHub pull request (https://github.com/nuxt/nuxt/pull/27134).

  3. To troubleshoot this, you might want to try using route rules to ensure these dynamic routes are properly handled in SSR mode. You can add route rules in your nuxt.config.ts file. For example:

    export default defineNuxtConfig({
      // ... your existing config
      routeRules: {
        '/wohnung-mieten/**': { ssr: true },
        '/suche/**': { ssr: true }
      }
    })
    

    This approach is mentioned in the Hybrid Rendering documentation (https://nuxt.com/docs/guide/concepts/rendering#hybrid-rendering).

  4. If the issue persists, it might be worth checking if there are any conflicts with Nuxt's auto-generated routes. You could try disabling auto-imports for pages temporarily to see if that affects the behavior.

#
  1. Another approach to consider is using the extendRouteRules method from the Nuxt kit, as mentioned in the Custom Routing documentation (https://nuxt.com/docs/guide/recipes/custom-routing#nuxt-module). This might provide more fine-grained control over how these routes are processed.

If none of these suggestions resolve the issue, it might be a bug in Nuxt's handling of dynamically added routes in SSR mode. In that case, it would be worth reporting this issue on the Nuxt GitHub repository (https://github.com/nuxt/nuxt) with a minimal reproduction of the problem.

Remember, hybrid rendering in Nuxt is a powerful feature, but it can sometimes lead to complex interactions between different rendering modes. Always ensure your route rules and rendering modes are consistently applied across your application.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@untold musk Kapa.ai is still learning and improving, please let me know how I did by reacting below.