Skip to content

fix: handle functional generate.routes#475

Merged
danielroe merged 4 commits intomainfrom
fix/generate-routes
Aug 25, 2022
Merged

fix: handle functional generate.routes#475
danielroe merged 4 commits intomainfrom
fix/generate-routes

Conversation

@danielroe
Copy link
Copy Markdown
Member

🔗 Linked issue

resolves #472

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Users who want to programmatically determine what routes should be prerendered should use a hook to do so:

import { defineNuxtConfig } from '@nuxt/bridge'

export default defineNuxtConfig({
  hooks: {
    async 'nitro:config' (config) {
      const routes = await getRoutes()
      config.prerender.routes.push(...routes)
    }
  }
})

In the mean time, for backward compatibility, we can call the generate.routes function.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Comment thread src/nitro.ts
delete nitroConfig.alias['#build']

if (nuxt.options.generate.routes instanceof Function) {
console.warn('It is recommended to migrate the `generate.routes` function to the `nitro:config` hook instead. See https://github.com/nuxt/bridge/pull/475.')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might intoroduce better nitro hook (in prerender: namespace) to allow extending async hooks. nitro:config is also for dev and nornal build.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed - I think it would be good to have such a hook. Updating this section to avoid calling it in dev/prepare.

@danielroe danielroe force-pushed the fix/generate-routes branch from ad6b951 to 2f3a2bb Compare August 12, 2022 22:42
@danielroe danielroe merged commit da95eff into main Aug 25, 2022
@danielroe danielroe deleted the fix/generate-routes branch August 25, 2022 09:28
@danielroe danielroe mentioned this pull request Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FATAL nuxt.options.generate.routes is not iterable

2 participants