Next.js Discord

Discord Forum

i18n blog redirect causes ui flash

Unanswered
Cinnamon posted this in #help-forum
Open in Discord
CinnamonOP
I have a next15 app
I am using next-intl

This is the country switcher (it is shared in layout.tsx)
<Select value={locale} onValueChange={(value: 'en'|'pl') => {
      router.push(pathName, {locale:value })
    }}
    ...



I have a /[locale]/blog and /[locale]/blog/[slug]
For the same blog entry (strapi blog) the slug depends on the locale
Artikel1 for de, and Article1 for en
When I click the country selector to change the locale, from de->en for example
I go from /de/blog/artikel1 -> /en/blog/artikel1
To finish the transition to /en/blog/article1 I have this code:
if(data[0].locale !== locale){
    const properArticle = data[0].localizations.find((item) => item.locale === locale);
    if(!properArticle) {
      notFound();
    }

    return redirect({
      href: `/blog/${properArticle.slug}`,
      locale: locale,
    })
  }

This results in two transitions.
All would be good, but the layout.tsx file is flashed briefly which ruins the UX. How do I fix this?

1 Reply

CinnamonOP
Current workaround: return return <BlogRedirect to={/blog/${properArticle.slug}} />

Where I do router.push
and make that BlogRedirect look a bit better than plain layout.tsx