The purpose of the go_router for Flutter is to use declarative routes to reduce complexity, regardless of the platform you're targeting (mobile, web, desktop), handling deep linking from Android, iOS and the web while still allowing an easy-to-use developer experience.
Originally posted by **Agondev** November 25, 2021
By wrapping the MaterialApp's builder's child with CallbackShortcut and passing various options of popping route, like
```Navigator.of(context)```
or
```context.pop()```
or
```GoRouterDelegate```
or
```_goRouter.pop()```
or
```Router.of(context).routerDelegate.popRoute()```
etc.
I get exceptions like
```Router operation requested with a context that does not include a Router.```
and
```No GoRouter found in context```.
Only thing that seems to kind of work is appRouter.navigator?.pop(), and that requires 2 attempts after the first time. With Auto Route it's enough to call ```_autoRoute.pop()``` from anywhere in the app using a shortcut of my choosing for it to pop the closest encompassing route.
Can the same not be done in GoRouter?
Example of my latest draft of MaterialApp
```dart
return MaterialApp.router(
routeInformationParser: _router.routeInformationParser,
routerDelegate: _router.routerDelegate,
builder: (context, child) {
CallbackShortcuts(
bindings: {
LogicalKeySet(
LogicalKeyboardKey.escape,
): () => appRouter.navigator?.pop(),
LogicalKeyboardKey.escape,
LogicalKeyboardKey.alt,
): () => appRouter.pop(), // or context.pop()
}
child: child!,
)
}
);
```
To reiterate, the first binding works in GoRouter after two attempts, the second one just throws. But it does work in Auto Route with no problems.
Discussed in https://github.com/csells/go_router/discussions/212