Router class final
Fluent router (BLUEPRINT_V2 §7.3.2). Routes are registered during boot and compiled once into per-method RadixTrees.
Constructors
- Router()
Properties
- baseUrl ↔ String
-
Base URL used for absolute URLs (set from
APP_URLat boot).getter/setter pair - fallbackRoute → RouteEntry?
-
The fallback route, if any.
no setter
- hasBindings → bool
-
Whether any route model binding is registered.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- isCompiled → bool
-
Whether compile has run.
no setter
-
patterns
→ Map<
String, RegExp> -
Router-wide parameter patterns (
Route::pattern).no setter -
routes
→ List<
RouteEntry> -
All registered routes in registration order.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- signer ↔ UrlSigner?
-
Signer used by signedUrl (set from
APP_KEYat boot).getter/setter pair
Methods
-
allowedMethods(
String path, {String? host}) → List< String> -
Methods that have a route for
path(used for405/OPTIONS). -
any(
String path, Handler handler) → RouteEntry -
Registers
handlerfor every standard method. -
apiResource(
String name, ResourceController controller, {List< String> ? only, List<String> ? except, Map<String, String> parameters = const <String, String>{}, List<Object> middleware = const <Object>[]}) → void -
Registers
index,store,show,update(PUT+PATCH) anddestroyforname(posts→/posts,/posts/{post}), namedposts.indexetc. Nested names (posts.comments) produce nested paths. -
bind(
String param, RouteBinder resolver, {bool orFail = true}) → void -
Resolves every route parameter named
paramthroughresolverafter the route's RunsBeforeBindings middleware (authentication, rate limits) and before the rest; the result is available viarequest.binding<T>(). WithorFail, anullresult renders a 404. -
bindModel<
T extends Model> (String param, ModelDefinition< T> definition) → void -
Route model binding:
{post}becomes aPost, read withrequest.binding<Post>('post'), or a 404. Explicit, because a Dart handler has no parameter types to tell a model from an id. -
compile(
MiddlewareRegistry registry) → void -
Builds the lookup trees and resolves middleware aliases. Validates that
route names are unique. Optional parameters are expanded into one tree
entry per prefix (
/posts/{id?}→/postsand/posts/{id}). -
delete(
String path, Handler handler) → RouteEntry -
A
DELETEroute. -
fallback(
Handler handler) → RouteEntry -
Registers the route used when nothing else matches a
GETrequest. -
get(
String path, Handler handler) → RouteEntry -
A
GET(andHEAD) route:router.get('/users/{id}', handler). -
group(
void routes(Router router), {String prefix = '', String name = '', List< Object> middleware = const <Object>[], Map<String, Object> where = const <String, Object>{}, bool scopeBindings = false, String? domain}) → void -
Registers routes with stacked
prefix,nameprefix,middlewareand parameter constraints (where). -
has(
String name) → bool -
Whether a route named
nameexists. -
hasValidSignature(
Request request) → bool -
Whether
requestcarries a valid signature produced by signedUrl. -
lookup(
String method, String path, {String? host}) → RouteMatch< RouteEntry> ? -
Looks up the route for
method+path, honouring constraints.HEADfalls back toGET. The fallback route (if any) answersGETrequests that match nothing else. -
match(
List< String> methods, String path, Handler handler) → RouteEntry -
Registers
handlerfor the givenmethods. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
options(
String path, Handler handler) → RouteEntry -
An
OPTIONSroute. -
patch(
String path, Handler handler) → RouteEntry -
A
PATCHroute. -
pattern(
String param, Object regex) → void -
Router-wide constraint for every parameter named
param. -
permanentRedirect(
String from, String to) → RouteEntry -
Permanent (
301) redirect. -
post(
String path, Handler handler) → RouteEntry -
A
POSTroute. -
put(
String path, Handler handler) → RouteEntry -
A
PUTroute. -
redirect(
String from, String to, {int status = 302}) → RouteEntry -
Redirects
fromtoto(302by default). -
resolveBindings(
Request request) → Future< Handler?> -
Runs the binders for the matched route of
request, in path order. Answers the route'smissinghandler when it should reply instead. -
resource(
String name, WebResourceController controller, {List< String> ? only, List<String> ? except, Map<String, String> parameters = const <String, String>{}, List<Object> middleware = const <Object>[]}) → void -
Like apiResource plus
createandeditfor HTML forms. -
signedUrl(
String name, {Map< String, Object?> params = const <String, Object?>{}, Map<String, Object?> query = const <String, Object?>{}, Duration? expires, bool absolute = true}) → String -
Generates a signed URL (absolute by default) that
ValidateSignatureMiddlewarecan verify;expiresadds expiry. -
toString(
) → String -
A string representation of this object.
inherited
-
url(
String name, {Map< String, Object?> params = const <String, Object?>{}, Map<String, Object?> query = const <String, Object?>{}, bool absolute = false}) → String -
Generates a path for the named route, substituting
paramsand appendingquery. Optional parameters may be omitted; withabsolutethe baseUrl is prepended. -
ws(
String path, WebSocketHandler handler, {bool compress = true, int maxPayloadBytes = Response.defaultWebSocketMaxPayloadBytes, int maxBufferedBytes = Response.defaultWebSocketMaxBufferedBytes, int slowClientCode = 1008}) → RouteEntry -
A WebSocket endpoint: the route's middleware (
auth,throttle, ...) runs first, then the connection is upgraded andhandlergets the socket and the request (route parameters,Auth.user()) in the request's scope. A plain request gets426 Upgrade Required. A WebSocket route;compressfalse turns permessage-deflate off, and a client with more thanmaxBufferedByteswaiting to be sent is closed withslowClientCode(see Response.webSocket).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited