fallback<T extends Object> static method

Route fallback<T extends Object>(
  1. dynamic controller
)

the route for a GET or HEAD request that matches no other route and no staticFiles file. Use it for a custom 404 page, or to send index.html of a single page app. Other methods still get 404 or 405.

Like other routes, it follows group, the router prefix, domain and middleware. So in a router, the global middleware runs for it. Inside a group, it only answers paths under the group prefix. When two fallbacks match, the one with the longest prefix wins.

Route.fallback((DoxRequest req) => res.status(404).json(...));
Route.group('admin', () {
  Route.fallback(controller); // only for /admin/...
});

Implementation

static Route fallback<T extends Object>(dynamic controller) {
  Route r = Route();
  RouteData data = r._routeData(
    HttpRequestMethod.GET,
    r._join(''),
    _action<T>(controller),
  );
  _fallbacks.add(data);
  r._last = data;
  r._lastGroup = null;
  return r;
}