resolveRedirects method
Follows guard redirects for location until navigation is allowed.
Returns the final location (with its BloomRouteMatch) after applying every guard redirect in the chain. A guard denying without a redirect target stops resolution and yields that location as blocked.
Throws BloomRedirectLoopException when the chain revisits a location
or exceeds maxRedirects hops (default 10) — e.g. route A redirecting
to B while B redirects back to A. Callers (such as the browser
router controller) must surface this instead of recursing forever.
Implementation
Future<GuardResolution> resolveRedirects(
String location, {
int maxRedirects = 10,
}) async {
final visited = <String>[];
var current = location;
while (true) {
final match = this.match(current);
if (match == null) {
return GuardResolution.noMatch(current);
}
final res = await evaluateGuards(match.route, current, match.params);
if (res.isAllowed || res.redirectPath == null) {
return GuardResolution(
location: current,
match: match,
blocked: !res.isAllowed,
);
}
final target = res.redirectPath!;
if (visited.contains(target) || visited.length >= maxRedirects) {
throw BloomRedirectLoopException(
[...visited, current],
target,
);
}
visited.add(current);
current = target;
}
}