Routemaster

Hello! Routemaster is an easy-to-use router for Flutter, which wraps over Navigator 2.0.

Features

  • Simple declarative mapping from a URLs to pages
  • Easy-to-use API: just Routemaster.of(context).push('/page')
  • Really easy nested navigation support for tabs
  • Multiple route maps: for example one for a logged in user, another for logged out

Here's the entire routing setup needed for an app featuring tabs and pushed routes:

final routes = RouteMap(routes: {
  '/': (_) => CupertinoTabPage(
        child: HomePage(),
        paths: ['feed', 'settings'],
      ),
  '/feed': (_) => MaterialPage<void>(child: FeedPage()),
  '/feed/profile/:id': (info) => MaterialPage<void>(child: ProfilePage(id: info['id'])),
  '/settings': (_) => MaterialPage<void>(child: SettingsPage()),
};

void main() {
  runApp(
      MaterialApp.router(
        routerDelegate: RoutemasterDelegate(routesBuilder: (context) => routes),
        routeInformationParser: RoutemasterParser(),
      ),
    );
}

And then to navigate:

Routemaster.of(context).push('/feed/profile/1');

...you can see this in action in this simple app example.

There's also a more advanced example.

I would love any feedback you have! Please create an issue for API feedback.

Please don't report bugs yet; it's way too early. There are almost no tests, so there will be bugs 😁

Design goals

  • Integrated: work with the Flutter Navigator 2.0 API, don't try to replace it. Try to have a very Flutter-like API.
  • Usable: design around user scenarios/stories, such as the ones in the Flutter storyboard - see here for examples.
  • Opinionated: don't provide 10 options to achieve a goal, but be flexible for all scenarios.
  • Focused: just navigation, nothing else. For example, no dependency injection.

This project builds on page_router.

Name

Named after the original Routemaster:

A photo of a Routemaster bus

(photo by Chris Sampson, licensed under CC BY 2.0)

Libraries

routemaster