match method
Implementation
List<RouterPathMatch<T>> match(String path) {
final url = Uri.tryParse(path);
final List<RouterPathMatch<T>> matches = [
RouterPathMatch<T>(
node: this,
parameters: {},
queryParameters: {},
)
];
if (url == null) {
if (kDebugMode) {
throw ArgumentError.value(path, 'path', 'Invalid path');
}
return matches;
}
final parts =
url.path.split('/').where((element) => element.isNotEmpty).toList();
var current = this;
final parameters = <String, String>{};
for (final part in parts) {
final node = current.children[part];
if (node == null) {
return [];
}
if (node.isParameter) {
parameters[node.name] = part;
}
if (node.data != null) {
matches.add(RouterPathMatch<T>(
node: node,
parameters: {...parameters},
queryParameters: url.queryParameters,
));
}
current = node;
}
if (current.data == null) {
if (kDebugMode) {
throw ArgumentError.value(path, 'path', 'Invalid path');
}
return [];
}
return matches;
}