toHierarchy static method

RouteMatch toHierarchy(
  1. List<RouteMatch> segments
)

Converts a list of linear route matches to to a hierarchy of routes e.g Match1,Match2,Match3 will be [Match1[Match2Match3]]

Implementation

static RouteMatch toHierarchy(List<RouteMatch> segments) {
  if (segments.length == 1) {
    return segments.first;
  } else {
    return segments.first.copyWith(children: [
      toHierarchy(
        segments.sublist(1, segments.length),
      ),
    ]);
  }
}