Skip to content
Source
Sign inSign up
TanStack/router

test(react-router): check the availability of the route context after a redirect on the first load #1710

MergedSeanCassieremerged 4 commits intomain fromrefs/pull/1710/headmerged by SeanCassiere

Showing 1 changed file with 184 additions and 0 deletions.

x
0 of 1 viewed, 1 left
184 additions and 0 deletionspackages/react-router/tests/routeContext.test.tsxModified
View file
@@ -10,6 +10,7 @@
RouterProvider,
useRouteContext,
rootRouteId,
+ redirect,
} from '../src'
​
import { sleep } from './utils'
@@ -133,6 +134,67 @@
expect(mock).toHaveBeenCalledWith({ foo: 'sean' })
expect(mock).toHaveBeenCalledTimes(1)
+​
+ // Check if context the context is available after a redirect
+ test('route context is present in the /about route after a redirect is thrown in the beforeLoad of the index route', async () => {
+ const mock = vi.fn()
+​
+ const rootRoute = createRootRoute()
+ const indexRoute = createRoute({
+ getParentRoute: () => rootRoute,
+ path: '/',
+ beforeLoad: async () => {
+ await sleep(WAIT_TIME)
+ throw redirect({ to: '/about' })
+ },