nuxt-community / redirect-module

No more cumbersome redirects for Nuxt 2!
MIT License
310 stars 17 forks source link

Nuxt 3 Support #130

Open harlan-zw opened 12 months ago

harlan-zw commented 12 months ago

Hey :wave: It looks like this module hasn't been updated for Nuxt 3. In an effort to improve the developer experience of modules, I've updated the module to clarify that it only supports Nuxt 2.

Alternatives:

export default defineNuxtConfig({
  routeRules: {
   // Redirects legacy urls
    '/old-page': { redirect: '/new-page' }
  }
})

@manniL I'm presuming it's safe to say this can be deprecated at some point, given https://github.com/nuxt-community/redirect-module/issues/120

manniL commented 12 months ago

Yes, absolutely 👍

ersah123 commented 6 months ago

This package enabled us to pull the redirect data from CMS and use it in runtime by using its middleware.
i think this is not possible with routeRules config from nuxt 3. Thats why i had to create my own local module for my use case. Do you advise me to contribute to this repo to make it compatible with nuxt 3, or create another public module?

manniL commented 6 months ago

@ersah123 You can still use a nitro servermiddleware and pull things in there (+store them). ☺️ Not necessarily needs a module

ersah123 commented 6 months ago

but nitro middleware is a runtime and it runs on every server request, right? So where can i pull the redirect data in build time and share with nitro middleware?

manniL commented 6 months ago

you can pull them on the first request (or during prerendering), then store them via unstorage (useStorage) and access them 👍

ersah123 commented 6 months ago

But then my initial page load speed will suffer since it is like 11k lines of redirect rules i have :( I really prefer to get them on build time

manniL commented 6 months ago

Only the first one, and as I said, you could still "warm up" that cache ☺️

harlan-zw commented 6 months ago

But then my initial page load speed will suffer since it is like 11k lines of redirect rules i have :( I really prefer to get them on build time

You should use CloudFlare bulk redirects or something with so many

ersah123 commented 6 months ago

But then my initial page load speed will suffer since it is like 11k lines of redirect rules i have :( I really prefer to get them on build time

You should use CloudFlare bulk redirects or something with so many

That's true. we will implement long term solution later since we are trying to do nuxt 2 - bridge - nuxt 3 migration right now. Thanks for the suggestion :)

ersah123 commented 6 months ago

@manniL , to update you and this topic, i have found a another solution for my use case which i believe was better as a short term solution. Im now using nitro plugin (defineNitroPlugin) to pull data redirect data on nitro initialisation and adding that data to nitroApp's event object as new key so that it is available in every request on runtime in middleware (defineEventHandler). There i check if the event is 404, then i run my redirect checks.