resolve method

bool resolve(
  1. String absolute,
  2. String relative,
  3. List<RoutingResult<T?>> out, {
  4. String method = 'GET',
  5. bool strip = true,
})

Finds the first Route that matches the given path, with the given method.

Implementation

bool resolve(
  String absolute,
  String relative,
  List<RoutingResult<T?>> out, {
  String method = 'GET',
  bool strip = true,
}) {
  final cleanRelative = strip == false
      ? relative
      : stripStraySlashes(relative);
  var scanner = SpanScanner(cleanRelative);

  bool crawl(Router<T> r) {
    var success = false;

    for (var route in r.routes) {
      var pos = scanner.position;

      if (route is SymlinkRoute<T>) {
        if (route.parser != null) {
          var pp = route.parser!;
          if (pp.parse(scanner).successful) {
            var s = crawl(route.router);
            if (s) success = true;
          }
        }

        scanner.position = pos;
      } else if (route.method == '*' || route.method == method) {
        var parseResult = route.parser?.parse(scanner);
        if (parseResult != null) {
          if (parseResult.successful && scanner.isDone) {
            var tailResult = parseResult.value?.tail ?? '';
            //print(tailResult);
            var result = RoutingResult<T>(
              parseResult: parseResult,
              params: parseResult.value!.params,
              shallowRoute: route,
              shallowRouter: this,
              tail: tailResult + scanner.rest,
            );
            out.add(result);
            success = true;
          }
        }
        scanner.position = pos;
      }
    }

    return success;
  }

  return crawl(this);
}