@esmx/router 3.0.0-rc.50 → 3.0.0-rc.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/matcher.mjs CHANGED
@@ -1,12 +1,15 @@
1
1
  import { compile, match } from "path-to-regexp";
2
2
  export function createMatcher(routes) {
3
3
  const compiledRoutes = createRouteMatches(routes);
4
- return (toURL, baseURL) => {
4
+ return (toURL, baseURL, cb) => {
5
5
  const matchPath = toURL.pathname.substring(baseURL.pathname.length - 1);
6
6
  const matches = [];
7
7
  const params = {};
8
8
  const collectMatchingRoutes = (routes2) => {
9
9
  for (const item of routes2) {
10
+ if (cb && !cb(item)) {
11
+ continue;
12
+ }
10
13
  if (item.children.length && collectMatchingRoutes(item.children)) {
11
14
  matches.unshift(item);
12
15
  return true;
package/dist/options.mjs CHANGED
@@ -29,22 +29,10 @@ function getBaseUrl(options) {
29
29
  base.search = base.hash = "";
30
30
  return base;
31
31
  }
32
- function filterRoutesByLayer(routes, layerMode) {
33
- return routes.filter((route) => {
34
- if (layerMode && route.layer !== true) return false;
35
- if (!layerMode && route.layer === true) return false;
36
- if (route.children)
37
- route.children = filterRoutesByLayer(route.children, layerMode);
38
- return true;
39
- });
40
- }
41
32
  export function parsedOptions(options = {}) {
42
33
  var _a, _b, _c, _d, _e, _f;
43
34
  const base = getBaseUrl(options);
44
- const routes = filterRoutesByLayer(
45
- (_a = options.routes) != null ? _a : [],
46
- options.layer || false
47
- );
35
+ const routes = (_a = options.routes) != null ? _a : [];
48
36
  return Object.freeze({
49
37
  rootStyle: options.rootStyle || false,
50
38
  root: options.root || "",
package/dist/route.mjs CHANGED
@@ -85,9 +85,16 @@ export class Route {
85
85
  const base = options.base;
86
86
  const toInput = resolveRouteLocationInput(routeOptions.toInput, from);
87
87
  const to = options.normalizeURL(parseLocation(toInput, base), from);
88
- const isSameOrigin = to.origin === base.origin;
89
- const isSameBase = to.pathname.startsWith(base.pathname);
90
- const match = isSameOrigin && isSameBase ? options.matcher(to, base) : null;
88
+ let match = null;
89
+ if (to.origin === base.origin && to.pathname.startsWith(base.pathname)) {
90
+ const isLayer = toType === RouteType.pushLayer;
91
+ match = options.matcher(to, base, (config) => {
92
+ if (isLayer) {
93
+ return config.layer !== false;
94
+ }
95
+ return config.layer !== true;
96
+ });
97
+ }
91
98
  if (match) {
92
99
  applyRouteParams(match, toInput, base, to);
93
100
  Object.assign(this.params, match.params);
package/dist/types.d.ts CHANGED
@@ -93,7 +93,7 @@ export interface RouteMatchResult {
93
93
  readonly matches: readonly RouteParsedConfig[];
94
94
  readonly params: Record<string, string | string[] | undefined>;
95
95
  }
96
- export type RouteMatcher = (targetURL: URL, baseURL: URL) => RouteMatchResult;
96
+ export type RouteMatcher = (to: URL, base: URL, cb?: (item: RouteParsedConfig) => boolean) => RouteMatchResult;
97
97
  /**
98
98
  * Route constructor options interface
99
99
  */
package/package.json CHANGED
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "devDependencies": {
34
34
  "@biomejs/biome": "1.9.4",
35
- "@esmx/lint": "3.0.0-rc.50",
35
+ "@esmx/lint": "3.0.0-rc.51",
36
36
  "@types/node": "^24.0.0",
37
37
  "@vitest/coverage-v8": "3.2.4",
38
38
  "happy-dom": "^18.0.1",
@@ -41,7 +41,7 @@
41
41
  "unbuild": "3.5.0",
42
42
  "vitest": "3.2.4"
43
43
  },
44
- "version": "3.0.0-rc.50",
44
+ "version": "3.0.0-rc.51",
45
45
  "type": "module",
46
46
  "private": false,
47
47
  "exports": {
@@ -60,5 +60,5 @@
60
60
  "template",
61
61
  "public"
62
62
  ],
63
- "gitHead": "7ec8747f78f4626941cb4da548b6df47df4df825"
63
+ "gitHead": "5556ca6bbaf29a673861c685a19414d5853b9166"
64
64
  }
package/src/matcher.ts CHANGED
@@ -3,7 +3,11 @@ import type { RouteConfig, RouteMatcher, RouteParsedConfig } from './types';
3
3
 
4
4
  export function createMatcher(routes: RouteConfig[]): RouteMatcher {
5
5
  const compiledRoutes = createRouteMatches(routes);
6
- return (toURL: URL, baseURL: URL) => {
6
+ return (
7
+ toURL: URL,
8
+ baseURL: URL,
9
+ cb?: (item: RouteParsedConfig) => boolean
10
+ ) => {
7
11
  const matchPath = toURL.pathname.substring(baseURL.pathname.length - 1);
8
12
  const matches: RouteParsedConfig[] = [];
9
13
  const params: Record<string, string | string[]> = {};
@@ -11,6 +15,9 @@ export function createMatcher(routes: RouteConfig[]): RouteMatcher {
11
15
  routes: RouteParsedConfig[]
12
16
  ): boolean => {
13
17
  for (const item of routes) {
18
+ if (cb && !cb(item)) {
19
+ continue;
20
+ }
14
21
  // Depth-first traversal
15
22
  if (
16
23
  item.children.length &&
package/src/options.ts CHANGED
@@ -61,27 +61,11 @@ function getBaseUrl(options: RouterOptions): URL {
61
61
  return base;
62
62
  }
63
63
 
64
- function filterRoutesByLayer(
65
- routes: RouteConfig[],
66
- layerMode: boolean
67
- ): RouteConfig[] {
68
- return routes.filter((route) => {
69
- if (layerMode && route.layer !== true) return false;
70
- if (!layerMode && route.layer === true) return false;
71
- if (route.children)
72
- route.children = filterRoutesByLayer(route.children, layerMode);
73
- return true;
74
- });
75
- }
76
-
77
64
  export function parsedOptions(
78
65
  options: RouterOptions = {}
79
66
  ): RouterParsedOptions {
80
67
  const base = getBaseUrl(options);
81
- const routes = filterRoutesByLayer(
82
- options.routes ?? [],
83
- options.layer || false
84
- );
68
+ const routes = options.routes ?? [];
85
69
  return Object.freeze<RouterParsedOptions>({
86
70
  rootStyle: options.rootStyle || false,
87
71
  root: options.root || '',
package/src/route.ts CHANGED
@@ -153,10 +153,22 @@ export class Route {
153
153
  const base = options.base;
154
154
  const toInput = resolveRouteLocationInput(routeOptions.toInput, from);
155
155
  const to = options.normalizeURL(parseLocation(toInput, base), from);
156
- const isSameOrigin = to.origin === base.origin;
157
- const isSameBase = to.pathname.startsWith(base.pathname);
158
- const match =
159
- isSameOrigin && isSameBase ? options.matcher(to, base) : null;
156
+ let match: RouteMatchResult | null = null;
157
+
158
+ // Check if URL origin matches base origin (protocol + hostname + port)
159
+ // If origins don't match, treat as external URL and don't attempt route matching
160
+ if (
161
+ to.origin === base.origin &&
162
+ to.pathname.startsWith(base.pathname)
163
+ ) {
164
+ const isLayer = toType === RouteType.pushLayer;
165
+ match = options.matcher(to, base, (config) => {
166
+ if (isLayer) {
167
+ return config.layer !== false;
168
+ }
169
+ return config.layer !== true;
170
+ });
171
+ }
160
172
 
161
173
  if (match) {
162
174
  applyRouteParams(match, toInput, base, to);
package/src/types.ts CHANGED
@@ -146,7 +146,11 @@ export interface RouteMatchResult {
146
146
  readonly params: Record<string, string | string[] | undefined>;
147
147
  }
148
148
 
149
- export type RouteMatcher = (targetURL: URL, baseURL: URL) => RouteMatchResult;
149
+ export type RouteMatcher = (
150
+ to: URL,
151
+ base: URL,
152
+ cb?: (item: RouteParsedConfig) => boolean
153
+ ) => RouteMatchResult;
150
154
 
151
155
  /**
152
156
  * Route constructor options interface