Skip to content

404 route handling does not work on page reload #12995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jrenjilian opened this issue Feb 10, 2025 · 3 comments · Fixed by #13500
Closed

404 route handling does not work on page reload #12995

jrenjilian opened this issue Feb 10, 2025 · 3 comments · Fixed by #13500

Comments

@jrenjilian
Copy link

I'm using React Router as a...

library

Reproduction

Repository

Core reproduction code:

const router = createBrowserRouter([
  {
    path: "",
    element: <Link to="/bad-route">bad route</Link>,
    errorElement: <p>404</p>,
    loader: () => ({ data: "data" }),
  },
]);

createRoot(document.getElementById("root")).render(
  <StrictMode>
    <RouterProvider router={router} />
  </StrictMode>
);

System Info

System:
    OS: macOS 15.3
    CPU: (12) arm64 Apple M2 Pro
    Memory: 89.75 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.13.1 - /usr/local/bin/node
    Yarn: 1.22.21 - /usr/local/bin/yarn
    npm: 10.9.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 133.0.6943.53
    Safari: 18.3
    Safari Technology Preview: 18.2
  npmPackages:
    react-router: ^7.1.5 => 7.1.5 
    vite: ^6.1.0 => 6.1.0

Used Package Manager

npm

Expected Behavior

When loading a route that doesn't exist in the route definition (logging No routes matched location..., I expect that the errorElement or ErrorBoundary is rendered

  1. when doing a client-side navigation to the not found route
  2. when reloading the page at the not found route

Actual Behavior

The errorElement/ErrorBoundary is rendered when doing a client-side navigation but not when reloading the page. Note that this only seems to break when the route has a loader defined — without it, both expectations are met.

This means that a user who mistypes a route or uses an outdated bookmark will get a white screen instead of 404 UI.

This worked in 7.1.3 but is broken in 7.1.4 onwards.

@brophdawg11
Copy link
Contributor

This is resolved by #13500 and will be available in the next release 👍

@brophdawg11 brophdawg11 added the awaiting release This issue has been fixed and will be released soon label Apr 29, 2025
@brophdawg11 brophdawg11 removed their assignment Apr 29, 2025
Copy link
Contributor

github-actions bot commented May 8, 2025

🤖 Hello there,

We just published version 7.6.0 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@github-actions github-actions bot removed the awaiting release This issue has been fixed and will be released soon label May 8, 2025
Copy link
Contributor

🤖 Hello there,

We just published version 7.6.1 which involves this issue. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants