| 132 | } |
| 133 | |
| 134 | export function nextRouteTable(context: ResolutionContext): NextTable { |
| 135 | const all = context.getNodesByKind('route'); |
| 136 | const cached = tables.get(context); |
| 137 | if (cached && cached.source === all) return cached; |
| 138 | const exact = new Map<string, Node>(); |
| 139 | const dynamic: RouteTable['dynamic'] = []; |
| 140 | const roots = new Set<string>(); |
| 141 | for (const node of all) { |
| 142 | const file = tablePage(node); |
| 143 | if (!file) continue; |
| 144 | exact.set(node.name, node); |
| 145 | if (node.name.includes(':')) dynamic.push({ node, segs: node.name.split('/').slice(1) }); |
| 146 | roots.add(file.root); |
| 147 | } |
| 148 | const table: NextTable = { source: all, exact, dynamic, roots: [...roots] }; |
| 149 | tables.set(context, table); |
| 150 | return table; |
| 151 | } |
| 152 | |
| 153 | /** `/users/${…}?tab=x` → `['users', '*']`; an absolute URL keeps its path; a relative href is nothing. */ |
| 154 | function hrefSegments(href: HrefLiteral): string[] | null { |