diff --git a/tree.go b/tree.go index 6f99223..1082629 100644 --- a/tree.go +++ b/tree.go @@ -293,6 +293,12 @@ walk: // 外部循环用于遍历和构建路由树 } } +func (n *node) copyChildren() []*node { + children := make([]*node, len(n.children)) + copy(children, n.children) + return children +} + // findWildcard 搜索通配符段并检查名称是否包含无效字符。 // 如果未找到通配符,则返回 -1 作为索引。 func findWildcard(path string) (wildcard string, i int, valid bool) { @@ -486,7 +492,7 @@ walk: // 外部循环用于遍历路由树 wildChild: n.wildChild, nType: n.nType, priority: n.priority, - children: n.children, + children: n.copyChildren(), handlers: n.handlers, fullPath: n.fullPath, },