setNewRoutePath method
Called by the Router when the Router.routeInformationProvider reports that a new route has been pushed to the application by the operating system.
Consider using a SynchronousFuture if the result can be computed synchronously, so that the Router does not need to wait for the next microtask to schedule a build.
Implementation
@override
Future<void> setNewRoutePath(RouteDecoder configuration) async {
final page = configuration.route;
if (page == null) {
// Route not found — push the notFoundRoute but preserve the
// original requested URL so the browser URL bar keeps the vanity
// slug (e.g. /serzenmontoya) and Sint.currentRoute returns it.
final requestedUrl =
configuration.pageSettings?.name ?? notFoundRoute.name;
_pushNotFoundWithOriginalUrl(requestedUrl);
return;
}
// Browser back/forward sync (1.5.0): if the requested URL already
// exists in the stack, pop the entries above it — completing their
// completers through the normal pop path — instead of pushing a
// duplicate that desyncs the browser history from the internal stack.
final targetName = configuration.pageSettings?.name;
if (targetName != null) {
final existingIndex = _activePages
.indexWhere((element) => element.pageSettings?.name == targetName);
if (existingIndex >= 0) {
if (existingIndex == _activePages.length - 1) {
// Already at the requested route — nothing to do.
return;
}
while (_activePages.length - 1 > existingIndex) {
_popWithResult();
}
notifyListeners();
return;
}
}
_push(configuration);
}