| Server IP : 159.203.156.69 / Your IP : 216.73.217.172 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/vinext/dist/routing/ |
Upload File : |
import { normalizePathnameForRouteMatch } from "./utils.js";
import { buildRouteTrie, trieMatch } from "./route-trie.js";
//#region src/routing/route-matching.ts
/**
* Shared route-match preamble used by both Pages Router and App Router.
*
* Both routers normalize URLs and call `trieMatch` with nearly-identical
* preamble: strip query, trailing-slash normalize, run
* `normalizePathnameForRouteMatch`, split into url parts, then look up via a
* per-routes-array trie cache. This module factors that out so each router
* just calls `matchRouteWithTrie(url, routes)`.
*/
function createRouteTrieCache() {
return /* @__PURE__ */ new WeakMap();
}
function getOrBuildTrie(cache, routes) {
let trie = cache.get(routes);
if (!trie) {
trie = buildRouteTrie(routes);
cache.set(routes, trie);
}
return trie;
}
/**
* Match a URL path against a list of routes via the shared preamble:
* 1. strip query string
* 2. trailing-slash normalize (preserving root "/")
* 3. run `normalizePathnameForRouteMatch`
* 4. split into url parts and look up via the (cached) trie
*
* Generic over the route shape; both Pages `Route` and App `AppRoute`
* satisfy `{ patternParts: string[] }`.
*/
function matchRouteWithTrie(url, routes, cache) {
const pathname = url.split("?")[0];
let normalizedUrl = pathname === "/" ? "/" : pathname.replace(/\/$/, "");
normalizedUrl = normalizePathnameForRouteMatch(normalizedUrl);
const urlParts = normalizedUrl.split("/").filter(Boolean);
return trieMatch(getOrBuildTrie(cache, routes), urlParts);
}
//#endregion
export { createRouteTrieCache, matchRouteWithTrie };
//# sourceMappingURL=route-matching.js.map