#[BUG] pending spinner + throw redirect at __root = react error

2 messages · Page 1 of 1 (latest)

fickle lotus
#
// __root.tsx
export const Route = createRootRouteWithContext<RouterContext>()({
  component: RootComponent,
  pendingMs: 0, // show spinnner immediately - error when `beforeLoad` is over. Set it to `1000` - no error
  pendingMinMs: 500,
  pendingComponent: () => {
    return <SpinnerScreen />;
  },
  errorComponent: (props) => <pre>{JSON.stringify(props.error, null, 2)}</pre>,
  async beforeLoad({ context, location }) {
    const user = await context.qc.ensureQueryData(sessionQueryOptions);
    if (location.pathname.startsWith(WelcomeRoute.to)) return;
    const redir = match(user.type)
      .with("edit_op", () =>
        !location.pathname.startsWith(EditSalesRoute.to)
          ? redirect({
              to: EditSalesRoute.to,
              replace: true,
            })
          : undefined,
      )
      .with(...)
      .exhaustive();
    if (redir) throw redir;
  },
});
#

[BUG] pending spinner + throw redirect at __root = react error