i18n: Page transition broken with nuxt-i18n

Version

v5.3.0

Reproduction link

https://github.com

Steps to reproduce

I have simple fade page transition

.page-enter-active {
  backface-visibility: hidden;
  will-change: opacity;
  opacity: 1;
  transition: opacity 450ms linear;
}

.page-leave-active {
  backface-visibility: hidden;
  will-change: opacity;
  opacity: 1;
  transition: opacity 450ms linear;
}

.page-enter {
  opacity: 0;
}

.page-leave-active {
  opacity: 0;
}

The problem is, when I change locale, text content changes instantly while page transition is not complete. In result I have a blink of content.

Is there’a a way to solve this?

What is expected ?

No blink, smooth transition

What is actually happening?

Transition broken, content blink

<div align="right">This bug report is available on Nuxt community (#c163)</div>

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 34

Commits related to this issue

Most upvoted comments

@lu40 thanks, but returning transition name should not be empty '' becouse it will be replaced to default. Should return any character, e.g:

export default function pageTransition (from, to) {
  const pageTransitionName = 'my-page-transition'
  if (!from || !to || !from.name || !to.name) return pageTransitionName
  return stripLocale(from.name) === stripLocale(to.name) ? '-' : pageTransitionName
}

@thariddler could you provide a gif of the issue? That is the routing? (from > to) Or did you solved it already?

simplescreenrecorder-2019-02-09_22 40 42

The transition is copy-pasted from the original issue description. @thariddler I guess this is the behaviour you were talking about?


For me the following workaround does the job:

// utils/page-transition.js

function stripLocale (name) {
  const routeNameSeperator = '__' // or whatever you set it to
  return name.substring(0, name.indexOf(routeNameSeperator))
}

export default function pageTransition (from, to) {
  const pageTransitionName = 'my-page-transition'
  if (!from || !to || !from.name || !to.name) return pageTransitionName
  return stripLocale(from.name) === stripLocale(to.name) ? '' : pageTransitionName
}


// pages/index.vue

import pageTransition from '~/utils/page-transition'
export default {
  transition: pageTransition
}

However this disables page transitions when switching the language instead of replacing the translated content smoothly while fading back in.

Try key in nuxt layouts.

<NuxtPage :page-key="route.fullPath" />

or either

<main :key="route.fullPath">
  <slot></slot>
</main>

Could it be possible to set the new locale after first page unmounted, and before next page renders ?

@tiretdusix Not possible at the moment. You’ll be able to do it only once my PR fixing this issue gets merged: https://github.com/nuxt-community/i18n-module/pull/963

Actually when page component actually switches is only known at the page component level (beforeRouteLeave option) and at router-view level (either through watching $route or the leave event of the transition). It’s not that easy or robust to hook into those…

Also looking for a solution for this!

Any update on this? I see there are some conflicts on that PR plus no more comments from the repo’s maintainers

Is there already a solution to this?

Looking 4 solution too!