route method

T route(
  1. Uri uri
)

Returns the matching T for uri as defined with the Segment tree

Implementation

T route(Uri uri) {
  /// This is a compromise between providing the conventional behavior of
  /// 'route '/' means homepage' and the fact that [uri.pathSegments] doesn't
  /// actually include slashes.
  ///
  /// Manually prepending '/' to the segments means that [RootSegment] parses
  /// the 'homepage' as one would expect without the need for a special
  /// implementation of [RootSegment.parse] just for this case.
  final segments = ['/', ...uri.pathSegments];
  final context = ParseContext<T>(uri);
  final result = parse(context, segments, createError);

  return result == null
      ? createError(context)
      : result.mapOrElse(
          (value) => value,
          (error) => error,
        );
}