Skip to content

Ability to dynamically set proper headers for redirects with the prefix strategy #3915

@hermes85pl

Description

@hermes85pl

Describe the feature

I am looking into using the prefix strategy with redirectOn: 'no prefix' enabled. This, however, causes some headaches on deployment to an environment with proper caching enabled (e.g., Netlify), as proper headers are not set.

Nuxt 4 is smart enough, e.g., to set netlify-vary header to query automatically for app routes that require it when deploying to Netlify as one of the platforms that are supported out of the box. One would expect that adding this module would not break it, but it does. In this example Netlify with ISR enabled (the recommended way) will cache the first redirect to one of the supported languages. To fix this scenario, the module should set the header to, e.g., query,cookie=language,language=en|fr (depending on how the cookie is named and which languages are actually supported).

The fix suggested above is the optimized approach. A much worse option would be to use the regular vary header that offers less option and could result in cache pollution, however could still work correctly from the end user's perspective.

Ideally the module should handle each official deployment target of Nuxt on its own. As an alternative, the module could at least provide an option to inject the logic related to setting custom headers to its redirection logic. Actually, it would be nice to have such a possibility anyway in order to handle some specific custom scenarios. Or is there such an option and I somehow missed it when looking for it?

As a side note, simply setting the above header for /** in Nuxt's routeRules is not a good option either, as in such case it is applied even to resources under /_nuxt/ and there is no way to disable it for them. So while a similar approach could easily work for / with redirectOn: 'root', the redirectOn: 'no prefix' option is more challenging.

Additional information

  • Would you be willing to help implement this feature?
  • Could this feature be implemented as a module?

Final checks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions