dvNotFoundRedirect function
Where dartvel.notFoundRedirect sends a path no route serves, or null to
leave the location alone.
Called from the generated top-level redirect. It asks whether anything
matched (GoRouterState.topRoute is null only when nothing did) rather
than reading GoRouterState.error: go_router never sets error on the
state a top-level redirect receives, so a check on it is never true and
the setting was silently ignored.
Leaves alone a path that already is to, so a target that is itself
unserved renders the 404 page instead of redirecting forever, and a path
a Studio page document is stored for, since redirecting would make that
page unreachable. dvStudioPagesRoute matching is not a page matching:
it answers every address, and one with no document is not found.
Implementation
String? dvNotFoundRedirect(GoRouterState state, String to) {
if (to.isEmpty) return null;
final GoRoute? matched = state.topRoute;
if (matched != null && matched.name != dvStudioPagesRouteName) return null;
final String path = state.uri.path;
if (path == to) return null;
if (DVPageStore.cached(path) != null) return null;
return to;
}