You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(routing): add NavigatorObserver support to MagicRouter (#34)
* feat(routing): add NavigatorObserver support to MagicRouter (#31)
MagicRouter.instance.addObserver() enables Sentry, Firebase Analytics,
and custom NavigatorObserver integration. Observers are passed to GoRouter
automatically. Registration enforces same pre-build guard as routes.
* fix(test): rename misleading observer test — GoRouter doesn't expose observers (#34)
Renamed 'observers are passed to GoRouter' → 'observers persist after
router build' since GoRouter doesn't publicly expose its observer list.
- Observer support: `MagicRouter.instance.addObserver(observer)` — must register before `routerConfig` is accessed. Passed to GoRouter `observers` param. Read-only via `observers` getter
See the [Middleware documentation](/basics/middleware) for details on creating custom middleware.
314
+
315
+
<aname="navigator-observers"></a>
316
+
## Navigator Observers
317
+
318
+
Register `NavigatorObserver` instances for analytics, monitoring, or performance tracking. Observers must be added before the router is built (typically in your `RouteServiceProvider`):
319
+
320
+
```dart
321
+
class RouteServiceProvider extends ServiceProvider {
final observers = MagicRouter.instance.observers; // List<NavigatorObserver> (unmodifiable)
443
+
```
444
+
445
+
Observers are passed to GoRouter's `observers` parameter automatically. Adding observers after `routerConfig` is accessed throws `StateError`.
446
+
423
447
## Gotchas
424
448
449
+
-**Observer Registration Timing:** Observers must be added before `routerConfig` is accessed, same as routes. Register in `RouteServiceProvider.boot()`.
425
450
-**Route Registration Timing:** Routes must be registered during `ServiceProvider.register()` or `boot()`. They cannot be added after `MagicRouter.instance.routerConfig` is accessed.
426
451
-**Middleware Next Required:** Middleware must call `next()` to allow the request to proceed. Failing to call it halts the pipeline.
427
452
-**Path Parameters:** Parameters are injected by position into the handler function. Ensure the function signature matches the number of parameters in the route.
0 commit comments