Skip to content
Discussion options

You must be logged in to vote

You won't be able to do this in pure SPA mode based on the underlying architecture of a SPA. The index.html used for SPA mode only renders the root route, and all other routes are lazily loaded via route.lazy. By throwing in a middleware before calling next, those routes are never loaded so the router has no idea that the edit/layout route has an error boundary so it has no choice but to bubble to the root route on initial load.

const middlewareThatThrows: unstable_MiddlewareFunction<undefined> = async (
  _args,
  next
) => {
  throw new Error("permission denied");

  // This is what runs route.lazy for the matched routes and loads their implementations
  // await next()
};

Throwing that…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@brophdawg11
Comment options

@VillePakarinenPosti
Comment options

@VillePakarinenPosti
Comment options

@brophdawg11
Comment options

@VillePakarinenPosti
Comment options

Answer selected by VillePakarinenPosti
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants