export const Route = createRootRouteWithContext<RouterContext>()({
component: RootComponent,
pendingMs: 0,
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;
},
});