@esmx/router 3.0.0-rc.112 → 3.0.0-rc.116
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 +3 -0
- package/dist/types.d.ts +38 -0
- package/package.json +2 -2
- package/src/matcher.ts +3 -0
- package/src/types.ts +39 -0
- package/LICENSE +0 -21
package/dist/matcher.mjs
CHANGED
|
@@ -13,6 +13,7 @@ export function createMatcher(routes, compiledRoutes = createRouteMatches(routes
|
|
|
13
13
|
matches.unshift(item);
|
|
14
14
|
return true;
|
|
15
15
|
}
|
|
16
|
+
if (item.requireIndex && item.children.length) continue;
|
|
16
17
|
const result = item.match(matchPath);
|
|
17
18
|
if (result) {
|
|
18
19
|
matches.unshift(item);
|
|
@@ -30,6 +31,7 @@ export function createMatcher(routes, compiledRoutes = createRouteMatches(routes
|
|
|
30
31
|
}
|
|
31
32
|
export function createRouteMatches(routes, base = "") {
|
|
32
33
|
return routes.map((route) => {
|
|
34
|
+
var _a;
|
|
33
35
|
const compilePath = joinPathname(route.path, base);
|
|
34
36
|
return {
|
|
35
37
|
...route,
|
|
@@ -37,6 +39,7 @@ export function createRouteMatches(routes, base = "") {
|
|
|
37
39
|
match: match(compilePath),
|
|
38
40
|
compile: compile(compilePath),
|
|
39
41
|
meta: route.meta || {},
|
|
42
|
+
requireIndex: (_a = route.requireIndex) != null ? _a : false,
|
|
40
43
|
children: Array.isArray(route.children) ? createRouteMatches(route.children, compilePath) : []
|
|
41
44
|
};
|
|
42
45
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -64,6 +64,42 @@ export interface RouteConfig {
|
|
|
64
64
|
beforeLeave?: RouteConfirmHook;
|
|
65
65
|
/** Mark this route as only effective in layer mode */
|
|
66
66
|
layer?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Require an index child route to match the parent path
|
|
69
|
+
*
|
|
70
|
+
* When set to `true`, the parent route will not match its own path
|
|
71
|
+
* if no child route matches. The parent route requires a `path: ''`
|
|
72
|
+
* index child route to match the parent path itself.
|
|
73
|
+
*
|
|
74
|
+
* - `requireIndex: false` (default): If no child route matches,
|
|
75
|
+
* the matcher falls back to matching the parent route itself
|
|
76
|
+
* - `requireIndex: true`: If no child route matches, the parent
|
|
77
|
+
* route is skipped entirely (no fallback to self-match)
|
|
78
|
+
*
|
|
79
|
+
* @default false
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // requireIndex: true - /A won't match without index child
|
|
84
|
+
* {
|
|
85
|
+
* path: '/A',
|
|
86
|
+
* requireIndex: true,
|
|
87
|
+
* children: [
|
|
88
|
+
* { path: '', component: IndexComponent }, // /A matches this
|
|
89
|
+
* { path: 'a', component: AComponent } // /A/a matches this
|
|
90
|
+
* ]
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* // Default behavior - /A matches even without index child
|
|
94
|
+
* {
|
|
95
|
+
* path: '/A',
|
|
96
|
+
* children: [
|
|
97
|
+
* { path: 'a', component: AComponent } // /A/a matches, /A also matches (parent self)
|
|
98
|
+
* ]
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
requireIndex?: boolean;
|
|
67
103
|
/**
|
|
68
104
|
* Route override function for hybrid app development
|
|
69
105
|
*
|
|
@@ -85,6 +121,8 @@ export interface RouteConfig {
|
|
|
85
121
|
override?: RouteConfirmHook;
|
|
86
122
|
}
|
|
87
123
|
export interface RouteParsedConfig extends RouteConfig {
|
|
124
|
+
/** Require an index child route to match the parent path (always has a value after parsing) */
|
|
125
|
+
requireIndex: boolean;
|
|
88
126
|
compilePath: string;
|
|
89
127
|
children: RouteParsedConfig[];
|
|
90
128
|
match: MatchFunction;
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"unbuild": "3.6.1",
|
|
40
40
|
"vitest": "3.2.4"
|
|
41
41
|
},
|
|
42
|
-
"version": "3.0.0-rc.
|
|
42
|
+
"version": "3.0.0-rc.116",
|
|
43
43
|
"type": "module",
|
|
44
44
|
"private": false,
|
|
45
45
|
"exports": {
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"template",
|
|
59
59
|
"public"
|
|
60
60
|
],
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "3e692857ccb65e7d1fdf689e30eb5d935e8bda77"
|
|
62
62
|
}
|
package/src/matcher.ts
CHANGED
|
@@ -28,6 +28,8 @@ export function createMatcher(
|
|
|
28
28
|
matches.unshift(item);
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
|
+
// At this point, children exist but none matched — if requireIndex is true, skip self-match
|
|
32
|
+
if (item.requireIndex && item.children.length) continue;
|
|
31
33
|
const result = item.match(matchPath);
|
|
32
34
|
if (result) {
|
|
33
35
|
matches.unshift(item);
|
|
@@ -56,6 +58,7 @@ export function createRouteMatches(
|
|
|
56
58
|
match: match(compilePath),
|
|
57
59
|
compile: compile(compilePath),
|
|
58
60
|
meta: route.meta || {},
|
|
61
|
+
requireIndex: route.requireIndex ?? false,
|
|
59
62
|
children: Array.isArray(route.children)
|
|
60
63
|
? createRouteMatches(route.children, compilePath)
|
|
61
64
|
: []
|
package/src/types.ts
CHANGED
|
@@ -114,6 +114,43 @@ export interface RouteConfig {
|
|
|
114
114
|
/** Mark this route as only effective in layer mode */
|
|
115
115
|
layer?: boolean;
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Require an index child route to match the parent path
|
|
119
|
+
*
|
|
120
|
+
* When set to `true`, the parent route will not match its own path
|
|
121
|
+
* if no child route matches. The parent route requires a `path: ''`
|
|
122
|
+
* index child route to match the parent path itself.
|
|
123
|
+
*
|
|
124
|
+
* - `requireIndex: false` (default): If no child route matches,
|
|
125
|
+
* the matcher falls back to matching the parent route itself
|
|
126
|
+
* - `requireIndex: true`: If no child route matches, the parent
|
|
127
|
+
* route is skipped entirely (no fallback to self-match)
|
|
128
|
+
*
|
|
129
|
+
* @default false
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // requireIndex: true - /A won't match without index child
|
|
134
|
+
* {
|
|
135
|
+
* path: '/A',
|
|
136
|
+
* requireIndex: true,
|
|
137
|
+
* children: [
|
|
138
|
+
* { path: '', component: IndexComponent }, // /A matches this
|
|
139
|
+
* { path: 'a', component: AComponent } // /A/a matches this
|
|
140
|
+
* ]
|
|
141
|
+
* }
|
|
142
|
+
*
|
|
143
|
+
* // Default behavior - /A matches even without index child
|
|
144
|
+
* {
|
|
145
|
+
* path: '/A',
|
|
146
|
+
* children: [
|
|
147
|
+
* { path: 'a', component: AComponent } // /A/a matches, /A also matches (parent self)
|
|
148
|
+
* ]
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
requireIndex?: boolean;
|
|
153
|
+
|
|
117
154
|
/**
|
|
118
155
|
* Route override function for hybrid app development
|
|
119
156
|
*
|
|
@@ -136,6 +173,8 @@ export interface RouteConfig {
|
|
|
136
173
|
}
|
|
137
174
|
|
|
138
175
|
export interface RouteParsedConfig extends RouteConfig {
|
|
176
|
+
/** Require an index child route to match the parent path (always has a value after parsing) */
|
|
177
|
+
requireIndex: boolean;
|
|
139
178
|
compilePath: string;
|
|
140
179
|
children: RouteParsedConfig[];
|
|
141
180
|
match: MatchFunction;
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020 Esmx Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|