({ blockerFn, disabled, ignoreBlocker }: BlockerTestOpts)
| 37 | } |
| 38 | |
| 39 | async 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({ |
no test coverage detected