question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Localized Paths reachable from other languages when using differentDomains

See original GitHub issue

Version

v5.3.0

Reproduction link

http://jsfiddle.com

Steps to reproduce

  • Set ‘differentDomains’ to true in i18n config.
  • Specify ‘domain’ for each item in locales
  • Add page-translations to ‘pages’
// nuxt.config.js
{
  i18n: {
    differentDomains: true,
    locales: [
      {
        code: 'de',
        domain: 'de.website.com'
      },
      {
        code: 'en',
        domain: 'en.website.com'
      }
    ],
    parsePages: false, 
    pages: {
      login:{
        de:'/anmelden',
        en:'/login',
      },
}

What is expected ?

de subdomain http://de.website.com/anmelden -> 200 http://de.website.com/login -> 404

en subdomain http://en.website.com/login -> 200 http://en.website.com/anmelden -> 404

What is actually happening?

de subdomain http://de.website.com/anmelden -> 200 http://de.website.com/login -> 200 // should be 404

en subdomain http://en.website.com/login -> 200 http://en.website.com/anmelden -> 200 // should be 404

Additional comments?

It is working as expected when not using custom domains:

de subdomain http://website.com/de/anmelden -> 200 http://website.com/de/login -> 404 // works

en subdomain http://website.com/en/login -> 200 http://website.com/en/anmelden -> 404 // works

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
Kapcashcommented, Feb 7, 2022

One workaroud I can think of is to create a global middleware that checks the current path matches the locale, and if not, redirects to the correct one:

const localePathsRedirectsOnLocalizedDomains: Middleware = ({ route, redirect, app }) => {
  /* get the localized path from the current route path
     if route.path === '/anmelden' but current locale is 'en' -> it will return '/login'
   */
  const expectedPath = app.localePath(route.path)

  // If the current path doesn't match the localized one, then we're not on the right path.
  if (route.path !== expectedPath) {
    // redirect to correct one
    redirect(301, expectedPath)
    // or send 404 page
    error({ statusCode: 404 })
  }
}

export default localePathsRedirectsOnLocalizedDomains
0reactions
nikolashaagcommented, Feb 7, 2022

Thanks for the quick response @Kapcash . I came up with a similar solution but was manually checking the routes against the router. I didn’t know about app.localePath 🙌 .

Can confirm that above workaround works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Localizing URLs for new language sites - Search Laboratory US
We examine why URL structures matter for SEO and how to incorporate special characters that you may find in different languages.
Read more >
How To Manage URLs On A Multi-Country ... - Marcello Brivio
So we moved everything under a “.com” domain, using subfolders for managing the different countries (and languages).
Read more >
i18n should not assume 1-1 matching between translated ...
Hi, I'm not too sure I understand. You have two blogs: Chinese and English, and they are generated using Docusaurus i18n, with English...
Read more >
Localization based on different domains - Laracasts
I'm a complete begginer in Laravel :) I want to have localization based on different domains with "mcamara/laravel-localization" package.
Read more >
multiple languages same pages shall I change the page URL ...
Not many users actually look at the URL path and there are usually other areas in which translations and localization can be improved...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found