Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homepage not redirecting to prefixed route when implementing "Wait for page transition" with ssr: false, and strategy: prefix #2820

Open
adesombergh opened this issue Feb 28, 2024 · 2 comments

Comments

@adesombergh
Copy link

Environment

  • Operating System: Linux
  • Node Version: v18.18.0
  • Nuxt Version: 3.8.0
  • CLI Version: 3.9.1
  • Nitro Version: 2.7.2
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, ssr, i18n
  • Runtime Modules: @nuxtjs/[email protected]
  • Build Modules: -

Reproduction

Stackblitz reproduction

To reproduce visit homepage without any prefix. You should get a 404 Page not found: /.

Project configuration:

  • Nuxt with ssr: false
  • I18n with strategy: "prefix"
  • I18n with skipSettingLocaleOnNavigate: true
  • NuxtPage with transition as described here
# nuxt.config.js
export default defineNuxtConfig({
  modules: ['@nuxtjs/i18n'],
  ssr: false,
  i18n: {
    ...,
    strategy: 'prefix',
    skipSettingLocaleOnNavigate: true,
  },
});
<template>
  <div>
    <LangSwitcher />
    <NuxtPage
      :transition="{
        name: 'page',
        mode: 'out-in',
        onBeforeEnter,
      }"
    />
  </div>
</template>

<script lang="ts" setup>
const { finalizePendingLocaleChange } = useI18n();

const onBeforeEnter = async () => {
  await finalizePendingLocaleChange();
};
</script>

<style>
.page-enter-active,
.page-leave-active {
  transition: all 0.4s;
}
.page-enter-from,
.page-leave-to {
  opacity: 0;
  filter: blur(1rem);
}
</style>

Describe the bug

When implementing the "Wait for page transition" (so that messages are updated after page transition and not before), in a project with ssr: false and strategy: "prefix", the un-prefixed homepage isn't redirecting to the prefixed route (/en, etc..), leading to a 404 Page not found: / error.

Additional context

No response

Logs

No response

@szulcus
Copy link

szulcus commented Mar 18, 2024

I have the same problem

@Tienisto
Copy link

I believe there is a bug in

if (import.meta.client && skipSettingLocaleOnNavigate) {

It needs to also check if the next route has i18n enabled or not. Currently, it seem to always set the locale based on the next route regardless if the next route has i18n or not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants