Skip to content

Non-existent i18n routes cause the entire domain to be erased when going back to base locale #5844

@Josh-Cena

Description

@Josh-Cena

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

If a route is created for the base locale but not for i18n ones, e.g. like the bug in #5553—well, not exactly a bug, just an inconsiderate move by the plugin author, going from the non-existent i18n route back to the base locale results in the full domain from being erased.

This is related to how we test what's a "fully qualified" domain:

function createUrl({
locale,
fullyQualified,
}: {
locale: string;
// For hreflang SEO headers, we need it to be fully qualified (full protocol/domain/path...)
// For locale dropdown, using a path is good enough
fullyQualified: boolean;
}) {
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl(
locale,
)}${pathnameSuffix}`;
}

Steps to reproduce

  1. Create a plugin, and add a route to only the base locale.
    async contentLoaded({actions}) {
      actions.addRoute({
        path: '/feature-requests',
        exact: false,
        component: '@site/src/featureRequests/FeatureRequestsPage',
      });
    },
  1. Go to http://docusaurus.io/zh-CN/feature-requests, and see the 404.
  2. Go back to the base locale through the locale dropdown.

Expected behavior

I'm taken to http://docusaurus.io/feature-requests, regardless if this page exists or not.

Actual behavior

I'm taken to http://feature-requests, an absolutely absurd URL to be in.

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Reproducible demo

No response

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionclosed: wontfixA fix will bring significant overhead, or is out of scope (for feature requests)domain: i18nRelated to the i18n system

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions