Introduction
Remix routing is built on the web Fetch API and provides a minimal, composable system for mapping incoming requests to request handlers and middleware. The router accepts a standardRequest and returns a Response, making it portable across all JavaScript runtimes.
Core Concepts
Routes and Route Maps
Routes are organized using route maps - declarative objects that define your entire route structure upfront with type-safe route names and request methods.Route objects:
Creating a Router
UsecreateRouter() to create a router instance:
Configuration options for the router
Mapping Routes to Handlers
Userouter.map() to connect routes to their handlers:
Handling Requests
The router uses the standard Fetch API to handle requests:Method-Specific Routing
Routers provide convenient methods for handling specific HTTP methods:Request Context
Every action and middleware receives acontext object with useful properties:
The request context object passed to all actions and middleware
Type-Safe Context Keys
UsecreateContextKey() to create type-safe keys for storing and retrieving values from the request context:
Router Methods
TheRouter interface provides these methods:
fetch()
Fetch a response from the router.The request input to fetch
The request init options
map()
Map a route or route map to an action or controller.The route/pattern or route map to match. Can be a string, RoutePattern, Route, or RouteMap.
The action or controller to invoke when the route(s) match.
HTTP Method Helpers
Convenient methods for specific HTTP methods:router.get(route, action)- Map a GET routerouter.post(route, action)- Map a POST routerouter.put(route, action)- Map a PUT routerouter.patch(route, action)- Map a PATCH routerouter.delete(route, action)- Map a DELETE routerouter.head(route, action)- Map a HEAD routerouter.options(route, action)- Map an OPTIONS route
Next Steps
Route Patterns
Learn about URL pattern matching and parameter extraction
Middleware
Add functionality with composable middleware
Controllers
Organize routes with nested controllers
Forms
Handle form submissions with type-safe actions