Skip to content

useBlocker breaks navigation on 404 page #4881

@rothsandro

Description

@rothsandro

Which project does this relate to?

Router

Describe the bug

If the user visits a non-existing page and the app uses a useBlocker() hook, the user can't navigate away from the page anymore. Clicking on a valid link will just throw an error Error: No route found for location /foo (with /foo being the 404 url).

Uncaught (in promise) Error: No route found for location /foo
    at getLocation
    at Object.blockerFnComposed [as blockerFn]
    at tryNavigation 
    at Object.push
    at RouterCore.commitLocation 
    at RouterCore.buildAndCommitLocation 
    at RouterCore.navigate 
    at handleClick 
    at chunk-ZMTB2JSC.js?v=c5950115:916:5
    at Array.forEach (<anonymous>)

Your Example Website or App

https://stackblitz.com/edit/github-jxfdqrcu?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Open the repro
  2. Append "/foo" to the preview URL to get the "Not found" error
  3. Click on "Home" or "About"

=> Navigation doesn't work, there's an error in the console.

Expected behavior

As a user, I expected that navigation is triggered but it's not.

Screenshots or Videos

No response

Platform

  • Router / Start Version: Router 1.130.12
  • OS: macOS
  • Browser: Brave
  • Browser Version: 1.81.131
  • Bundler: Vite
  • Bundler Version: 6.3.5

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions