-
BREAKING CHANGE: Renamed "route handlers" terminology to "controller/action" throughout the package. This is a breaking change for anyone using the types or properties from this package. Update your code:
// Before import type { RouteHandlers } from '@remix-run/fetch-router' let routeHandlers = { middleware: [auth()], handlers: { home() { return new Response('Home') }, admin: { middleware: [requireAdmin()], handler() { return new Response('Admin') }, }, }, } satisfies RouteHandlers<typeof routes> router.map(routes, routeHandlers) // After import type { Controller } from '@remix-run/fetch-router' let controller = { middleware: [auth()], actions: { home() { return new Response('Home') }, admin: { middleware: [requireAdmin()], action() { return new Response('Admin') }, }, }, } satisfies Controller<typeof routes> router.map(routes, controller)
Summary of changes:
RouteHandlerstype =>ControllerRouteHandlertype =>ActionBuildRouteHandlertype =>BuildActionhandlersproperty =>actionshandlerproperty =>action
-
BREAKING CHANGE: Renamed
formActionroute helper toformand moved route helpers tolib/route-helpers/subdirectory. Update your imports:// Before import { route, formAction } from '@remix-run/fetch-router' let routes = route({ login: formAction('/login'), }) // After import { route, form } from '@remix-run/fetch-router' let routes = route({ login: form('/login'), })
The
FormActionOptionstype has also been renamed toFormOptions. -
BREAKING CHANGE: The
middlewareproperty is now required (not optional) in controller and action objects that use the{ middleware, actions }or{ middleware, action }format. This eliminates ambiguity when route names likeactioncollide with theactionproperty name.// Before: { action } without middleware was allowed router.any(routes.home, { action() { return new Response('Home') }, }) // After: just use a plain request handler function instead router.any(routes.home, () => { return new Response('Home') }) // Before: { actions } without middleware was allowed router.map(routes, { actions: { home() { return new Response('Home') }, }, }) // After: just use a plain controller object instead router.map(routes, { home() { return new Response('Home') }, }) // With middleware, the syntax remains the same (but middleware is now required) router.map(routes, { middleware: [auth()], actions: { home() { return new Response('Home') }, }, })
-
Add functional aliases for creating routes that respond to a single request method
import { del, get, patch, post } from '@remix-run/fetch-router' let routes = route({ home: get('/'), login: post('/login'), logout: post('/logout'), profile: { show: get('/profile'), edit: get('/profile/edit'), update: patch('/profile'), destroy: del('/profile'), }, })