clone method

Router<T> clone()

Returns a Router with a duplicated version of this tree.

Implementation

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

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

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