reroute testing

This commit is contained in:
Nate Kelley 2025-09-24 13:50:20 -06:00
parent 9c256b2312
commit 4199e948be
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
6 changed files with 101 additions and 20 deletions

View File

@ -2,3 +2,4 @@ export const BUSTER_HOME_PAGE = 'https://buster.so';
export const BUSTER_DOCS_URL = 'https://docs.buster.so'; export const BUSTER_DOCS_URL = 'https://docs.buster.so';
export const BUSTER_GETTING_STARTED_URL = 'https://www.buster.so/get-started'; export const BUSTER_GETTING_STARTED_URL = 'https://www.buster.so/get-started';
export const BUSTER_DOCS_QUICKSTART = 'https://docs.buster.so/docs/getting-started/quickstart'; export const BUSTER_DOCS_QUICKSTART = 'https://docs.buster.so/docs/getting-started/quickstart';
export const BUSTER_SIGN_UP_URL = 'https://buster.so/sign-up';

View File

@ -22,6 +22,7 @@ import { Route as InfoGettingStartedRouteImport } from './routes/info/getting-st
import { Route as AuthResetPasswordRouteImport } from './routes/auth.reset-password' import { Route as AuthResetPasswordRouteImport } from './routes/auth.reset-password'
import { Route as AuthLogoutRouteImport } from './routes/auth.logout' import { Route as AuthLogoutRouteImport } from './routes/auth.logout'
import { Route as AuthLoginRouteImport } from './routes/auth.login' import { Route as AuthLoginRouteImport } from './routes/auth.login'
import { Route as AppThrow2RouteImport } from './routes/app.throw2'
import { Route as AppThrowRouteImport } from './routes/app.throw' import { Route as AppThrowRouteImport } from './routes/app.throw'
import { Route as AppSettingsRouteImport } from './routes/app/_settings' import { Route as AppSettingsRouteImport } from './routes/app/_settings'
import { Route as AppAppRouteImport } from './routes/app/_app' import { Route as AppAppRouteImport } from './routes/app/_app'
@ -213,6 +214,11 @@ const AuthLoginRoute = AuthLoginRouteImport.update({
path: '/login', path: '/login',
getParentRoute: () => AuthRoute, getParentRoute: () => AuthRoute,
} as any) } as any)
const AppThrow2Route = AppThrow2RouteImport.update({
id: '/throw2',
path: '/throw2',
getParentRoute: () => AppRoute,
} as any)
const AppThrowRoute = AppThrowRouteImport.update({ const AppThrowRoute = AppThrowRouteImport.update({
id: '/throw', id: '/throw',
path: '/throw', path: '/throw',
@ -946,6 +952,7 @@ export interface FileRoutesByFullPath {
'/embed': typeof EmbedRouteWithChildren '/embed': typeof EmbedRouteWithChildren
'/healthcheck': typeof HealthcheckRoute '/healthcheck': typeof HealthcheckRoute
'/app/throw': typeof AppThrowRoute '/app/throw': typeof AppThrowRoute
'/app/throw2': typeof AppThrow2Route
'/auth/login': typeof AuthLoginRoute '/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute '/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute '/auth/reset-password': typeof AuthResetPasswordRoute
@ -1056,6 +1063,7 @@ export interface FileRoutesByTo {
'/healthcheck': typeof HealthcheckRoute '/healthcheck': typeof HealthcheckRoute
'/app': typeof AppSettingsRestricted_layoutAdmin_onlyRouteWithChildren '/app': typeof AppSettingsRestricted_layoutAdmin_onlyRouteWithChildren
'/app/throw': typeof AppThrowRoute '/app/throw': typeof AppThrowRoute
'/app/throw2': typeof AppThrow2Route
'/auth/login': typeof AuthLoginRoute '/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute '/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute '/auth/reset-password': typeof AuthResetPasswordRoute
@ -1151,6 +1159,7 @@ export interface FileRoutesById {
'/app/_app': typeof AppAppRouteWithChildren '/app/_app': typeof AppAppRouteWithChildren
'/app/_settings': typeof AppSettingsRouteWithChildren '/app/_settings': typeof AppSettingsRouteWithChildren
'/app/throw': typeof AppThrowRoute '/app/throw': typeof AppThrowRoute
'/app/throw2': typeof AppThrow2Route
'/auth/login': typeof AuthLoginRoute '/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute '/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute '/auth/reset-password': typeof AuthResetPasswordRoute
@ -1277,6 +1286,7 @@ export interface FileRouteTypes {
| '/embed' | '/embed'
| '/healthcheck' | '/healthcheck'
| '/app/throw' | '/app/throw'
| '/app/throw2'
| '/auth/login' | '/auth/login'
| '/auth/logout' | '/auth/logout'
| '/auth/reset-password' | '/auth/reset-password'
@ -1387,6 +1397,7 @@ export interface FileRouteTypes {
| '/healthcheck' | '/healthcheck'
| '/app' | '/app'
| '/app/throw' | '/app/throw'
| '/app/throw2'
| '/auth/login' | '/auth/login'
| '/auth/logout' | '/auth/logout'
| '/auth/reset-password' | '/auth/reset-password'
@ -1481,6 +1492,7 @@ export interface FileRouteTypes {
| '/app/_app' | '/app/_app'
| '/app/_settings' | '/app/_settings'
| '/app/throw' | '/app/throw'
| '/app/throw2'
| '/auth/login' | '/auth/login'
| '/auth/logout' | '/auth/logout'
| '/auth/reset-password' | '/auth/reset-password'
@ -1701,6 +1713,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof AuthLoginRouteImport preLoaderRoute: typeof AuthLoginRouteImport
parentRoute: typeof AuthRoute parentRoute: typeof AuthRoute
} }
'/app/throw2': {
id: '/app/throw2'
path: '/throw2'
fullPath: '/app/throw2'
preLoaderRoute: typeof AppThrow2RouteImport
parentRoute: typeof AppRoute
}
'/app/throw': { '/app/throw': {
id: '/app/throw' id: '/app/throw'
path: '/throw' path: '/throw'
@ -3235,6 +3254,7 @@ interface AppRouteChildren {
AppAppRoute: typeof AppAppRouteWithChildren AppAppRoute: typeof AppAppRouteWithChildren
AppSettingsRoute: typeof AppSettingsRouteWithChildren AppSettingsRoute: typeof AppSettingsRouteWithChildren
AppThrowRoute: typeof AppThrowRoute AppThrowRoute: typeof AppThrowRoute
AppThrow2Route: typeof AppThrow2Route
AppIndexRoute: typeof AppIndexRoute AppIndexRoute: typeof AppIndexRoute
} }
@ -3242,6 +3262,7 @@ const AppRouteChildren: AppRouteChildren = {
AppAppRoute: AppAppRouteWithChildren, AppAppRoute: AppAppRouteWithChildren,
AppSettingsRoute: AppSettingsRouteWithChildren, AppSettingsRoute: AppSettingsRouteWithChildren,
AppThrowRoute: AppThrowRoute, AppThrowRoute: AppThrowRoute,
AppThrow2Route: AppThrow2Route,
AppIndexRoute: AppIndexRoute, AppIndexRoute: AppIndexRoute,
} }

View File

@ -1,23 +1,42 @@
import { createFileRoute } from '@tanstack/react-router'; import { createFileRoute, useNavigate } from '@tanstack/react-router';
import { useState } from 'react'; import { z } from 'zod';
import { useMount } from '../hooks/useMount'; import { useMount } from '../hooks/useMount';
export const Route = createFileRoute('/app/throw')({ export const Route = createFileRoute('/app/throw')({
validateSearch: z.object({
iterations: z.number().optional(),
}),
component: RouteComponent, component: RouteComponent,
beforeLoad: ({ search }) => {
return {
iterations: search.iterations,
};
},
loader: async ({ context }) => {
return {
iterations: context.iterations,
};
},
head: ({ loaderData }) => {
return {
meta: [
{
title: `Throw ${loaderData?.iterations}`,
},
],
};
},
}); });
function RouteComponent() { function RouteComponent() {
const [throwError, setThrowError] = useState(false); const navigate = useNavigate();
const { iterations } = Route.useSearch();
useMount(() => { useMount(() => {
setTimeout(() => { setTimeout(() => {
setThrowError(true); navigate({ to: '/app/throw2', replace: true, search: { iterations: (iterations ?? 0) + 1 } });
}, 1000); }, 1000);
}); });
if (throwError) { return <div className="bg-red-100">Hello "/app/throw"! </div>;
throw new Error('Nate is testing this error');
}
return <div>Hello "/app/throw"! {throwError ? 'Throwing error' : 'Not throwing error'}</div>;
} }

View File

@ -0,0 +1,43 @@
import { createFileRoute, useNavigate } from '@tanstack/react-router';
import { z } from 'zod';
import { useMount } from '@/hooks/useMount';
const searchParamsSchema = z.object({
iterations: z.number().optional(),
});
export const Route = createFileRoute('/app/throw2')({
validateSearch: searchParamsSchema,
component: RouteComponent,
beforeLoad: ({ search }) => {
return {
iterations: search.iterations,
};
},
loader: async ({ context }) => {
return {
iterations: context.iterations,
};
},
head: ({ loaderData }) => {
return {
meta: [
{
title: `Throw ${loaderData?.iterations}`,
},
],
};
},
});
function RouteComponent() {
const navigate = useNavigate();
const { iterations } = Route.useSearch();
useMount(() => {
setTimeout(() => {
navigate({ to: '/app/throw', replace: true, search: { iterations: (iterations ?? 0) + 1 } });
}, 1000);
});
return <div className="bg-blue-100">Hello "/app/throw2"!</div>;
}

View File

@ -3,6 +3,7 @@ import { prefetchGetMyUserInfo } from '@/api/buster_rest/users/queryRequests';
import { getAppLayout } from '@/api/server-functions/getAppLayout'; import { getAppLayout } from '@/api/server-functions/getAppLayout';
import { AppProviders } from '@/context/Providers'; import { AppProviders } from '@/context/Providers';
import { getSupabaseSession } from '@/integrations/supabase/getSupabaseUserClient'; import { getSupabaseSession } from '@/integrations/supabase/getSupabaseUserClient';
import { BUSTER_SIGN_UP_URL } from '../config/externalRoutes';
export const Route = createFileRoute('/app')({ export const Route = createFileRoute('/app')({
context: ({ context }) => ({ ...context, getAppLayout }), context: ({ context }) => ({ ...context, getAppLayout }),
@ -27,7 +28,7 @@ export const Route = createFileRoute('/app')({
try { try {
const [user] = await Promise.all([prefetchGetMyUserInfo(queryClient)]); const [user] = await Promise.all([prefetchGetMyUserInfo(queryClient)]);
if (!user || !user.organizations || user.organizations.length === 0) { if (!user || !user.organizations || user.organizations.length === 0) {
throw redirect({ href: 'https://buster.so/sign-up', replace: true, statusCode: 307 }); throw redirect({ href: BUSTER_SIGN_UP_URL, replace: true, statusCode: 307 });
} }
return { return {
supabaseSession, supabaseSession,

View File

@ -1,13 +1,9 @@
import { createFileRoute } from '@tanstack/react-router'; import { createFileRoute, redirect } from '@tanstack/react-router';
import { useEffect } from 'react'; import { BUSTER_SIGN_UP_URL } from '../../config/externalRoutes';
export const Route = createFileRoute('/info/getting-started')({ export const Route = createFileRoute('/info/getting-started')({
component: GettingStartedPage, component: () => null,
beforeLoad: () => {
throw redirect({ href: BUSTER_SIGN_UP_URL, replace: true, statusCode: 307 });
},
}); });
export default function GettingStartedPage() {
useEffect(() => {
window.location.replace('https://buster.so/sign-up');
}, []);
return null;
}