Skip to content

Customized 404 not applied for docs/ sub routes #9665

Open

Description

@peterpeterparker

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

Follow-up of discussion #9664.

It seems that swizzled 404 are resolved when a root URL is accessed but, not when a sub-route is loaded.

e.g.

http://localhost:3000/unknown -> custom 404
http://localhost:3000/docs/unknown -> default 404 (or custom 404 for a milli seconds and default afterwards)

Reproducible demo

No response

Steps to reproduce

git clone https://github.com/peterpeterparker/docusaurus-404
cd docusaurus-404
npm ci
npm run start

try various unknown routes

Expected behavior

Custom 404 displayed for any 404 regardless of the (sub)route.

Actual behavior

As described in the details.

Your environment

No response

Self-service

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

Activity

  1. added
    bugAn error in the Docusaurus core causing instability or issues with its execution
    status: needs triageThis issue has not been triaged by maintainers
    on Dec 22, 2023
  2. murali-krishna-sv commented on Dec 29, 2023

    @murali-krishna-sv

    Looks like only for the docs route, the 404 content comes from NotFoundContent. As the DocRoot 404 is having this - https://github.com/facebook/docusaurus/blob/main/packages/docusaurus-theme-classic/src/theme/DocRoot/index.tsx#L24

    This was added to fix double layout issue for 404 in docs - ca177b3

    Maybe we have to update swizzle plugin to emit or wrap NotFoundContent component instead of NotFound. Instead of this docusaurus swizzle "@docusaurus/theme-classic" "NotFound" it should be changed to docusaurus swizzle "@docusaurus/theme-classic" "NotFoundContent".

    Or else we have to move the content from NotFound.js to NotFoundContent.js, that should fix this issue and somehow make sure this is documented.

  3. changed the title [-]404 not working on sub routes[/-] on Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its execution

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions