clone method

Router<T> clone ()

Returns a Router with a duplicated version of this tree.

Implementation

Router<T> clone() {
  final router = new Router<T>();
  final newMounted = new Map<Pattern, Router<T>>.from(mounted);

  for (var route in routes) {
    if (route is! SymlinkRoute<T>) {
      router._routes.add(route.clone());
    } else if (route is SymlinkRoute<T>) {
      final newRouter = route.router.clone();
      newMounted[route.path] = newRouter;
      final symlink = new SymlinkRoute<T>(route.path, newRouter);
      router._routes.add(symlink);
    }
  }

  return router.._mounted.addAll(newMounted);
}