Router<T> class
An abstraction over complex Route trees. Use this instead of the raw API. :)
- Implementers
Constructors
- Router()
-
Provide a
root
to make this Router revolve around a pre-defined route. Not recommended.
Properties
Methods
-
addRoute(
String method, String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to the given path for requests with the given method (case-insensitive). Provide '*' as the method to respond to all methods.
-
all(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to any request matching the given path.
-
chain(
Iterable< T> middleware) → ChainedRouter<T> -
Prepends the given
middleware
to any routes created by the resulting router. -
clone(
) → Router< T> - Returns a Router with a duplicated version of this tree.
-
delete(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to a DELETE request.
-
dumpTree(
{dynamic callback(String tree)?, String header = 'Dumping route tree:', String tab = ' '}) → void -
Creates a visual representation of the route hierarchy and
passes it to a callback. If none is provided,
print
is called. -
enableCache(
) → void - Enables the use of a cache to eliminate the overhead of consecutive resolutions of the same path.
-
get(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to a GET request.
-
group(
String path, void callback(Router< T> router), {Iterable<T> middleware = const [], String name = ''}) → SymlinkRoute<T> - Creates a route, and allows you to add child routes to it via a Router instance.
-
groupAsync(
String path, FutureOr< void> callback(Router<T> router), {Iterable<T> middleware = const [], String name = ''}) → Future<SymlinkRoute< T> > - Asynchronous equivalent of group.
-
head(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to a HEAD request.
-
mount(
String path, Router< T> router) → SymlinkRoute<T> - Incorporates another Router's routes into this one's.
- Generates a URI string based on the given input. Handy when you have named routes.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
options(
String path, T handler, {Iterable< T> middleware = const {}}) → Route<T> - Adds a route that responds to a OPTIONS request.
-
patch(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to a PATCH request.
-
post(
String path, T handler, {Iterable< T> middleware = const []}) → Route<T> - Adds a route that responds to a POST request.
-
put(
String path, T handler, {Iterable< T> middleware = const []}) → Route - Adds a route that responds to a PUT request.
-
resolve(
String absolute, String relative, List< RoutingResult< out, {String method = 'GET', bool strip = true}) → boolT?> > - Finds the first Route that matches the given path, with the given method.
-
resolveAbsolute(
String path, {String method = 'GET', bool strip = true}) → Iterable< RoutingResult< T> > -
Returns the result of resolve with
path
passed as bothabsolute
andrelative
. -
resolveAll(
String absolute, String relative, {String method = 'GET', bool strip = true}) → Iterable< RoutingResult< T> > - Finds every possible Route that matches the given path, with the given method.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited