go_router_modular
Modular dependency injection and per-module routing built on top of
go_router. Split your Flutter app into
self-contained modules — each owning its routes, its dependencies, and its
lifecycle — and let the package wire everything together and dispose of it
automatically.
Why modules?
A growing Flutter app tends to collect a single giant route table and one global
dependency container. go_router_modular breaks that apart:
- Encapsulation — a module declares its own routes and binds. Nothing leaks out unless you export it.
- Automatic lifecycle — a module’s dependencies are registered when you enter it and disposed when you leave. No manual cleanup, no leaks.
- Familiar routing — it’s
go_routerunderneath, so deep links, the URL bar, and browser history all work as you expect.
A minimal app
lib/main.dart
import 'package:flutter/material.dart';
import 'package:go_router_modular/go_router_modular.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Modular.configure(
appModule: AppModule(),
initialRoute: '/',
);
runApp(const AppWidget());
}
class AppWidget extends StatelessWidget {
const AppWidget({super.key});
@override
Widget build(BuildContext context) => ModularApp.router(title: 'My App');
}lib/src/app_module.dart
class AppModule extends Module {
@override
List<ModularRoute> get routes => [
ModuleRoute('/', module: HomeModule()),
];
}lib/src/modules/home/home_module.dart
class HomeModule extends Module {
@override
FutureOr<void> binds(Injector i) {
i.addSingleton<HomeController>((i) => HomeController());
}
@override
List<ModularRoute> get routes => [
ChildRoute('/', child: (context, state) => const HomePage()),
];
}New here? Start with the Quick Start — it gets a modular app running in three steps.
Explore the docs
Last updated on