Prerendering custom routes does not work as intented..
My directory is like follows:
And the
router.options.ts
has the content as shown in the screenshot. What the router options effectively does uses the subdomain retreived from the nitro middleware and only returns the routes that belong to the respective folder: admin.localhost:3000
--> $admin/index.vue
, etc. It is configured such that localhost:3000/
points to $www/index.vue
.
I want to pre-render all the routes in the www subdomain. I tried saying "/": { prerender: true }
and "/$www/**": { prerender: true }
but they both don't work. What can I do?3 Replies
Hi @cybercoder-naj. 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, it appears that your specific use case with subdomains and custom routing is not directly addressed. However, I can provide some insights and suggestions based on related information about prerendering in Nuxt.
The issue you're facing is likely related to how Nuxt handles prerendering with custom routing configurations. The standard prerendering methods might not be aware of your subdomain-based routing setup.
Here are some potential approaches you could try:
1. Use
nitro.prerender.routes
:
Instead of using routeRules
, you can try specifying the routes explicitly in your nuxt.config.ts
:
This approach is mentioned in the Nuxt documentation on prerendering (https://nuxt.com/docs/getting-started/prerendering#selective-pre-rendering).
2. Use the prerenderRoutes
utility:
You could try using the prerenderRoutes
utility in your pages to hint additional routes for prerendering. This might work if your custom routing is resolved at runtime. You would need to call this from a page that is already being prerendered:
This is described in the Nuxt documentation on runtime prerender configuration (https://nuxt.com/docs/getting-started/prerendering#runtime-prerender-configuration).
3. Use the prerender:routes
Nuxt hook:
You could use this hook to add your custom routes for prerendering. In your nuxt.config.ts
:
This approach is mentioned in the Nuxt documentation on prerendering (https://nuxt.com/docs/getting-started/prerendering#prerenderroutes-nuxt-hook).
4. Consider using addPrerenderRoutes
:
If you're creating a custom module, you could use the addPrerenderRoutes
utility from the Nuxt Kit:
This is described in the Nuxt Kit documentation (https://nuxt.com/docs/api/kit/nitro#addprerenderroutes).
Given your custom routing setup, you might need to experiment with these approaches to find the one that works best with your specific configuration. If none of these solutions work, you might need to consider adjusting your routing strategy or creating a custom build step to generate the prerendered pages.
Remember that the effectiveness of these solutions may depend on how your custom routing interacts with Nuxt's build process. You might need to combine multiple approaches or create a more custom solution tailored to your specific setup.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@711113525023735809> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
This problem isn't solved yet 😦 would like some help