decode method
Decodes a path using the route pattern.
Path parameters will be stored in the returned Route object.
Implementation
Route decode(String path) {
final match = routeMatchExp.firstMatch(path);
if (match == null) {
throw ApiException('Could not match pattern.');
}
final pathParams = Map.fromEntries(match.groupNames
.where((e) => e != _wildcardGroup)
.map((e) =>
(match.groupNames.contains(e) && match.namedGroup(e) != null)
? MapEntry(e, Uri.decodeComponent(match.namedGroup(e)!))
: null)
.whereNotNull);
final wildcard = match.groupNames.contains(_wildcardGroup)
? match.namedGroup(_wildcardGroup)
: null;
return Route(this, path, pathParams, wildcard);
}