auto_routes StackRouter carries navigatorKey. Apps use that to reach a BuildContext from a router-typed receiver:
extension AppLaunchers on StackRouter {
Future<void> launchSupport() async {
if (navigatorKey.currentContext case final context?) {
return context.read<SupportLauncher>().open();
}
}
}
This pattern is often load-bearing rather than incidental. The router receiver acts as a capability gate: app services are reachable only from somewhere that legitimately holds a router — i.e. a routing layer — instead of from any widget in the tree. Moving those extensions onto BuildContext would make the services callable everywhere, which is usually the thing the design was preventing.
KaiselRouterConfig exposes navigatorKey, but KaiselRouter does not, and the router has no route back to its config or delegate. So such extensions cannot be ported by retyping the receiver from StackRouter to KaiselRouter<R>.
Workaround, and why it is unsatisfying
Hoist the key to a top-level final and hand it to the config:
final appNavigatorKey = GlobalKey<NavigatorState>();
final config = KaiselRouterConfig<AppRoute>(navigatorKey: appNavigatorKey, /* ... */);
extension AppLaunchers on KaiselRouter<AppRoute> {
Future<void> launchSupport() async {
if (appNavigatorKey.currentContext case final context?) { /* ... */ }
}
}
Works, but the key is now app state rather than router state, and there are two sources of truth if anyone also passes a key to the config.
Suggestion
Expose navigatorKey (or the owning delegate) on KaiselRouter<R>, so extension on KaiselRouter<R> can reach a context the way extension on StackRouter could. This is also a prerequisite for a clean maybePop implementation — see the related issue.
auto_routes
StackRoutercarriesnavigatorKey. Apps use that to reach aBuildContextfrom a router-typed receiver:This pattern is often load-bearing rather than incidental. The router receiver acts as a capability gate: app services are reachable only from somewhere that legitimately holds a router — i.e. a routing layer — instead of from any widget in the tree. Moving those extensions onto
BuildContextwould make the services callable everywhere, which is usually the thing the design was preventing.KaiselRouterConfigexposesnavigatorKey, butKaiselRouterdoes not, and the router has no route back to its config or delegate. So such extensions cannot be ported by retyping the receiver fromStackRoutertoKaiselRouter<R>.Workaround, and why it is unsatisfying
Hoist the key to a top-level
finaland hand it to the config:Works, but the key is now app state rather than router state, and there are two sources of truth if anyone also passes a key to the config.
Suggestion
Expose
navigatorKey(or the owning delegate) onKaiselRouter<R>, soextension on KaiselRouter<R>can reach a context the wayextension on StackRoutercould. This is also a prerequisite for a cleanmaybePopimplementation — see the related issue.