You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This works identically on server (SSR) and client (navigation). At SSR time, the handler is called directly. In the browser, it makes an HTTP request to `/api/todos`.
224
+
This works identically on server (SSR) and client (navigation). At SSR time, the handler is called directly. In the browser, it makes an HTTP request to `/api/todos`. Passing `signal` ensures in-flight API calls are cancelled when the user navigates away.
217
225
218
226
### Components
219
227
@@ -235,32 +243,35 @@ The callback passed to `callApiPromise` returns an `Effect`, so you can compose
235
243
import { Effect } from"effect";
236
244
237
245
// Combine multiple API calls
238
-
loader: () =>
239
-
callApiPromise((api) =>
240
-
Effect.all({
241
-
todos: api.todos.list(),
242
-
stats: api.dashboard.stats(),
243
-
}),
246
+
loader: ({ abortController }) =>
247
+
callApiPromise(
248
+
(api) =>
249
+
Effect.all({
250
+
todos: api.todos.list(),
251
+
stats: api.dashboard.stats(),
252
+
}),
253
+
{ signal: abortController.signal },
244
254
),
245
255
```
246
256
247
257
### Protected routes
248
258
249
-
Use a layout route with `beforeLoad` to check auth before loading child routes:
259
+
Use a layout route with `beforeLoad` to check auth before loading child routes. `throwOnTag` maps Effect error tags to thrown values — TanStack Router intercepts these to trigger redirects, `notFound()`, etc.
Creates a convenience function that resolves the `ApiClient` from the appropriate runtime and runs the effect as a `Promise`. Designed for use in route loaders and event handlers.
|`throwOnTag`|`Record<string, (e) => any>`| Global error mappings — keys are error `_tag` strings, handlers return a value to throw (e.g. `notFound()`) |
0 commit comments