Router class final
A tree of routes, composed at startup.
The shape follows axum: build one with route, nest others under a path with nest, add middleware with layer, and attach dependencies with withState.
final app = Router()
..route('/health', get(health))
..nest('/api/v1', v1)
..layer(Cors())
..withState(repo);
- Implemented types
- Available extensions
Constructors
- Router({Object? metadata, int? bodyLimit, void onError(Object error, StackTrace stack)?})
- Creates an empty router.
-
Router.module({String prefix = '', List<
Route> routes = const [], Object? metadata}) -
Creates the router a generated module exposes.
factory
Properties
- bodyLimit → int?
-
The body limit, read from the outermost router.
final
- handler → Handler
-
The composed shelf handler.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- metadata → Object?
-
Anything an add-on wants to hang off this router.
final
- onError → void Function(Object error, StackTrace stack)?
-
The error sink, read from the outermost router.
final
- prefix → String
-
The prefix this router contributes, normalized.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
call(
Request request) → FutureOr< Response> -
Answers
request, so a router is usable wherever a Handler is.override -
describe(
) → List< MountedRoute> -
Available on Router, provided by the RouterDescribe extension
Every route below this router, with the path it serves. -
fallback(
Handler handler) → void - Answers requests no route matched, instead of the default 404.
-
layer(
Object middleware) → void -
Wraps everything below this router in
middleware. -
merge(
Router router) → void -
Mounts
routerat this router's own path, adding no prefix. -
mount(
String path, Handler handler) → void -
Hands everything under
pathtohandler. -
nest(
String path, Router router) → void -
Mounts
routerunderpath. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
route(
String path, MethodRouter methods) → void -
Serves
methodsatpath, relative to this router. -
routeLayer(
Object middleware) → void -
Wraps only the routes below this router in
middleware. -
toString(
) → String -
A string representation of this object.
inherited
-
withState<
T extends Object> (T value) → void -
Attaches state that
@State() Thandlers below this router read.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited