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