redirectTo method

Future<void> redirectTo(
  1. String name,
  2. [Map params,
  3. int code]
)

Redirects to the given named Route.

Implementation

Future<void> redirectTo(String name, [Map params, int code]) async {
  if (!isOpen) throw closed();
  Route _findRoute(Router r) {
    for (Route route in r.routes) {
      if (route is SymlinkRoute) {
        final m = _findRoute(route.router);

        if (m != null) return m;
      } else if (route.name == name) return route;
    }

    return null;
  }

  Route matched = _findRoute(app);

  if (matched != null) {
    await redirect(
        matched.makeUri(params.keys.fold<Map<String, dynamic>>({}, (out, k) {
          return out..[k.toString()] = params[k];
        })),
        code: code);
    return;
  }

  throw ArgumentError.notNull('Route to redirect to ($name)');
}