Skip to content
Discussion options

You must be logged in to vote

This is a serialization issue. When beforeLoad throws your custom ForbiddenError, TanStack Router serializes it to send from server to client during hydration. Custom class instances don't survive that serialization — you get a plain Error on the client side, and missedPermissions is gone.

Two approaches:

1. Use data on a plain Error (simplest)

Instead of a custom class, attach your data to a regular Error via a serializable property:

beforeLoad: () => {
  const error = new Error("403 - Forbidden");
  (error as any).data = {
    type: "ForbiddenError",
    missedPermissions: ["A", "B", "C"],
  };
  throw error;
},

Then in errorComponent:

defaultErrorComponent: ({ error }) => {
  const data =

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DJafari
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