removeRoute method

void removeRoute(
  1. String path
)

Implementation

void removeRoute(String path) {
  final segments = _parsePath(path);
  var currentNode = _root;
  RouteNode? nodeToDelete;

  // Traverse the tree to find the node to delete
  for (final segment in segments) {
    final child = currentNode.findChild(segment);
    if (child == null) {
      return; // Node not found, nothing to delete
    }
    if (child.nodeSegments.length == segments.length) {
      nodeToDelete = child;
      break;
    }
    currentNode = child;
  }

  if (nodeToDelete == null) {
    return; // Node not found, nothing to delete
  }

  final parent = nodeToDelete.parent!;
  parent.nodeSegments.remove(nodeToDelete);
}