MCPcopy
hub / github.com/TanStack/router / setup

Function setup

packages/react-router/tests/blocker.test.tsx:39–118  ·  view source on GitHub ↗
({ blockerFn, disabled, ignoreBlocker }: BlockerTestOpts)

Source from the content-addressed store, hash-verified

37}
38
39async function setup({ blockerFn, disabled, ignoreBlocker }: BlockerTestOpts) {
40 const _mockBlockerFn = vi.fn(blockerFn)
41 const rootRoute = createRootRoute()
42 const indexRoute = createRoute({
43 getParentRoute: () => rootRoute,
44 path: '/',
45 component: function Setup() {
46 const navigate = useNavigate()
47 useBlocker({ disabled, shouldBlockFn: _mockBlockerFn })
48 return (
49 <>
50 <h1>Index</h1>
51 <Link to="/posts" ignoreBlocker={ignoreBlocker}>
52 link to posts
53 </Link>
54 <Link to="/foo">link to foo</Link>
55 <button onClick={() => navigate({ to: '/posts', ignoreBlocker })}>
56 button
57 </button>
58 </>
59 )
60 },
61 })
62
63 const postsRoute = createRoute({
64 getParentRoute: () => rootRoute,
65 path: '/posts',
66 component: () => (
67 <>
68 <h1>Posts</h1>
69 </>
70 ),
71 })
72
73 const fooRoute = createRoute({
74 getParentRoute: () => rootRoute,
75 path: '/foo',
76 beforeLoad: () => {
77 throw redirect({ to: '/bar' })
78 },
79 component: () => (
80 <>
81 <h1>Foo</h1>
82 </>
83 ),
84 })
85
86 const barRoute = createRoute({
87 getParentRoute: () => rootRoute,
88 path: '/bar',
89 component: () => (
90 <>
91 <h1>Bar</h1>
92 </>
93 ),
94 })
95
96 const router = createRouter({

Callers 1

blocker.test.tsxFile · 0.70

Calls 8

createRootRouteFunction · 0.90
createRouteFunction · 0.90
useNavigateFunction · 0.90
useBlockerFunction · 0.90
redirectFunction · 0.90
createRouterFunction · 0.90
renderFunction · 0.90
navigateFunction · 0.50

Tested by

no test coverage detected