| 3 | |
| 4 | // This can be removed when https://github.com/unjs/radix3/pull/73 is fixed |
| 5 | function remove(ctx: RadixRouterContext, path: string) { |
| 6 | let success = false; |
| 7 | const sections = path.split("/"); |
| 8 | let node = ctx.rootNode; |
| 9 | |
| 10 | for (const section of sections) { |
| 11 | // @ts-expect-error tempfile |
| 12 | node = node.children.get(section); |
| 13 | if (!node) { |
| 14 | return success; |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | if (node.data) { |
| 19 | const lastSection = sections[-1]; |
| 20 | node.data = null; |
| 21 | if (node.children.size === 0) { |
| 22 | const parentNode = node.parent; |
| 23 | // @ts-expect-error tempfile |
| 24 | parentNode.children.delete(lastSection); |
| 25 | // @ts-expect-error tempfile |
| 26 | parentNode.wildcardChildNode = null; |
| 27 | // @ts-expect-error tempfile |
| 28 | parentNode.placeholderChildNode = null; |
| 29 | } |
| 30 | success = true; |
| 31 | } |
| 32 | |
| 33 | return success; |
| 34 | } |
| 35 | |
| 36 | export default remove; |