loadRouter function

Future<VoyagerRouter> loadRouter(
  1. Future<List<VoyagerPath>> paths,
  2. List<VoyagerPlugin<Voyager>> plugins, {
  3. VoyagerFactory<Voyager>? voyagerFactory,
})

given paths and plugins resolves you a router.

Implementation

Future<VoyagerRouter> loadRouter(
    Future<List<VoyagerPath>> paths, List<VoyagerPlugin> plugins,
    {VoyagerFactory? voyagerFactory}) {
  final router = voyagerFactory != null
      ? VoyagerRouter(voyagerFactory: voyagerFactory)
      : VoyagerRouter();

  plugins.forEach((plugin) {
    router.registerPlugin(plugin);
  });

  return paths.then((paths) {
    paths.forEach((path) {
      router.registerPath(path);
    });
  }).then((_) {
    return router;
  });
}