@tanstack/react-router 0.0.1-beta.62 → 0.0.1-beta.64
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/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +0 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +50 -50
- package/build/umd/index.development.js +153 -116
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +0 -1
package/build/stats-react.json
CHANGED
|
@@ -7,31 +7,31 @@
|
|
|
7
7
|
"name": "index.production.js",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"uid": "
|
|
10
|
+
"uid": "8d6c-103",
|
|
11
11
|
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"name": "node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
15
|
-
"uid": "
|
|
15
|
+
"uid": "8d6c-105"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"name": "packages",
|
|
19
19
|
"children": [
|
|
20
20
|
{
|
|
21
21
|
"name": "store/build/esm/index.js",
|
|
22
|
-
"uid": "
|
|
22
|
+
"uid": "8d6c-107"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"name": "router/build/esm/index.js",
|
|
26
|
-
"uid": "
|
|
26
|
+
"uid": "8d6c-109"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"name": "react-store/build/esm/index.js",
|
|
30
|
-
"uid": "
|
|
30
|
+
"uid": "8d6c-111"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"name": "react-router/src/index.tsx",
|
|
34
|
-
"uid": "
|
|
34
|
+
"uid": "8d6c-113"
|
|
35
35
|
}
|
|
36
36
|
]
|
|
37
37
|
}
|
|
@@ -41,155 +41,155 @@
|
|
|
41
41
|
"isRoot": true
|
|
42
42
|
},
|
|
43
43
|
"nodeParts": {
|
|
44
|
-
"
|
|
44
|
+
"8d6c-103": {
|
|
45
45
|
"renderedLength": 429,
|
|
46
46
|
"gzipLength": 238,
|
|
47
47
|
"brotliLength": 0,
|
|
48
|
-
"mainUid": "
|
|
48
|
+
"mainUid": "8d6c-102"
|
|
49
49
|
},
|
|
50
|
-
"
|
|
50
|
+
"8d6c-105": {
|
|
51
51
|
"renderedLength": 181,
|
|
52
52
|
"gzipLength": 129,
|
|
53
53
|
"brotliLength": 0,
|
|
54
|
-
"mainUid": "
|
|
54
|
+
"mainUid": "8d6c-104"
|
|
55
55
|
},
|
|
56
|
-
"
|
|
56
|
+
"8d6c-107": {
|
|
57
57
|
"renderedLength": 1288,
|
|
58
58
|
"gzipLength": 497,
|
|
59
59
|
"brotliLength": 0,
|
|
60
|
-
"mainUid": "
|
|
60
|
+
"mainUid": "8d6c-106"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
63
|
-
"renderedLength":
|
|
64
|
-
"gzipLength":
|
|
62
|
+
"8d6c-109": {
|
|
63
|
+
"renderedLength": 45412,
|
|
64
|
+
"gzipLength": 10895,
|
|
65
65
|
"brotliLength": 0,
|
|
66
|
-
"mainUid": "
|
|
66
|
+
"mainUid": "8d6c-108"
|
|
67
67
|
},
|
|
68
|
-
"
|
|
68
|
+
"8d6c-111": {
|
|
69
69
|
"renderedLength": 1571,
|
|
70
70
|
"gzipLength": 594,
|
|
71
71
|
"brotliLength": 0,
|
|
72
|
-
"mainUid": "
|
|
72
|
+
"mainUid": "8d6c-110"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
75
|
-
"renderedLength":
|
|
76
|
-
"gzipLength":
|
|
74
|
+
"8d6c-113": {
|
|
75
|
+
"renderedLength": 12077,
|
|
76
|
+
"gzipLength": 3154,
|
|
77
77
|
"brotliLength": 0,
|
|
78
|
-
"mainUid": "
|
|
78
|
+
"mainUid": "8d6c-112"
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"nodeMetas": {
|
|
82
|
-
"
|
|
82
|
+
"8d6c-102": {
|
|
83
83
|
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
84
84
|
"moduleParts": {
|
|
85
|
-
"index.production.js": "
|
|
85
|
+
"index.production.js": "8d6c-103"
|
|
86
86
|
},
|
|
87
87
|
"imported": [],
|
|
88
88
|
"importedBy": [
|
|
89
89
|
{
|
|
90
|
-
"uid": "
|
|
90
|
+
"uid": "8d6c-112"
|
|
91
91
|
}
|
|
92
92
|
]
|
|
93
93
|
},
|
|
94
|
-
"
|
|
94
|
+
"8d6c-104": {
|
|
95
95
|
"id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
96
96
|
"moduleParts": {
|
|
97
|
-
"index.production.js": "
|
|
97
|
+
"index.production.js": "8d6c-105"
|
|
98
98
|
},
|
|
99
99
|
"imported": [],
|
|
100
100
|
"importedBy": [
|
|
101
101
|
{
|
|
102
|
-
"uid": "
|
|
102
|
+
"uid": "8d6c-108"
|
|
103
103
|
}
|
|
104
104
|
]
|
|
105
105
|
},
|
|
106
|
-
"
|
|
106
|
+
"8d6c-106": {
|
|
107
107
|
"id": "/packages/store/build/esm/index.js",
|
|
108
108
|
"moduleParts": {
|
|
109
|
-
"index.production.js": "
|
|
109
|
+
"index.production.js": "8d6c-107"
|
|
110
110
|
},
|
|
111
111
|
"imported": [],
|
|
112
112
|
"importedBy": [
|
|
113
113
|
{
|
|
114
|
-
"uid": "
|
|
114
|
+
"uid": "8d6c-108"
|
|
115
115
|
}
|
|
116
116
|
]
|
|
117
117
|
},
|
|
118
|
-
"
|
|
118
|
+
"8d6c-108": {
|
|
119
119
|
"id": "/packages/router/build/esm/index.js",
|
|
120
120
|
"moduleParts": {
|
|
121
|
-
"index.production.js": "
|
|
121
|
+
"index.production.js": "8d6c-109"
|
|
122
122
|
},
|
|
123
123
|
"imported": [
|
|
124
124
|
{
|
|
125
|
-
"uid": "
|
|
125
|
+
"uid": "8d6c-104"
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
|
-
"uid": "
|
|
128
|
+
"uid": "8d6c-106"
|
|
129
129
|
}
|
|
130
130
|
],
|
|
131
131
|
"importedBy": [
|
|
132
132
|
{
|
|
133
|
-
"uid": "
|
|
133
|
+
"uid": "8d6c-112"
|
|
134
134
|
}
|
|
135
135
|
]
|
|
136
136
|
},
|
|
137
|
-
"
|
|
137
|
+
"8d6c-110": {
|
|
138
138
|
"id": "/packages/react-store/build/esm/index.js",
|
|
139
139
|
"moduleParts": {
|
|
140
|
-
"index.production.js": "
|
|
140
|
+
"index.production.js": "8d6c-111"
|
|
141
141
|
},
|
|
142
142
|
"imported": [
|
|
143
143
|
{
|
|
144
|
-
"uid": "
|
|
144
|
+
"uid": "8d6c-115"
|
|
145
145
|
}
|
|
146
146
|
],
|
|
147
147
|
"importedBy": [
|
|
148
148
|
{
|
|
149
|
-
"uid": "
|
|
149
|
+
"uid": "8d6c-112"
|
|
150
150
|
}
|
|
151
151
|
]
|
|
152
152
|
},
|
|
153
|
-
"
|
|
153
|
+
"8d6c-112": {
|
|
154
154
|
"id": "/packages/react-router/src/index.tsx",
|
|
155
155
|
"moduleParts": {
|
|
156
|
-
"index.production.js": "
|
|
156
|
+
"index.production.js": "8d6c-113"
|
|
157
157
|
},
|
|
158
158
|
"imported": [
|
|
159
159
|
{
|
|
160
|
-
"uid": "
|
|
160
|
+
"uid": "8d6c-102"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
|
-
"uid": "
|
|
163
|
+
"uid": "8d6c-114"
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
|
-
"uid": "
|
|
166
|
+
"uid": "8d6c-108"
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
|
-
"uid": "
|
|
169
|
+
"uid": "8d6c-110"
|
|
170
170
|
}
|
|
171
171
|
],
|
|
172
172
|
"importedBy": [],
|
|
173
173
|
"isEntry": true
|
|
174
174
|
},
|
|
175
|
-
"
|
|
175
|
+
"8d6c-114": {
|
|
176
176
|
"id": "react",
|
|
177
177
|
"moduleParts": {},
|
|
178
178
|
"imported": [],
|
|
179
179
|
"importedBy": [
|
|
180
180
|
{
|
|
181
|
-
"uid": "
|
|
181
|
+
"uid": "8d6c-112"
|
|
182
182
|
}
|
|
183
183
|
],
|
|
184
184
|
"isExternal": true
|
|
185
185
|
},
|
|
186
|
-
"
|
|
186
|
+
"8d6c-115": {
|
|
187
187
|
"id": "use-sync-external-store/shim/with-selector",
|
|
188
188
|
"moduleParts": {},
|
|
189
189
|
"imported": [],
|
|
190
190
|
"importedBy": [
|
|
191
191
|
{
|
|
192
|
-
"uid": "
|
|
192
|
+
"uid": "8d6c-110"
|
|
193
193
|
}
|
|
194
194
|
],
|
|
195
195
|
"isExternal": true
|
|
@@ -345,6 +345,21 @@
|
|
|
345
345
|
function hasObjectPrototype(o) {
|
|
346
346
|
return Object.prototype.toString.call(o) === '[object Object]';
|
|
347
347
|
}
|
|
348
|
+
function partialDeepEqual(a, b) {
|
|
349
|
+
if (a === b) {
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
if (typeof a !== typeof b) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
if (isPlainObject(a) && isPlainObject(b)) {
|
|
356
|
+
return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
|
|
357
|
+
}
|
|
358
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
359
|
+
return a.length === b.length && a.every((item, index) => partialDeepEqual(item, b[index]));
|
|
360
|
+
}
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
348
363
|
|
|
349
364
|
function joinPaths(paths) {
|
|
350
365
|
return cleanPath(paths.filter(Boolean).join('/'));
|
|
@@ -614,15 +629,10 @@
|
|
|
614
629
|
this.children = children;
|
|
615
630
|
return this;
|
|
616
631
|
};
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
// false,
|
|
621
|
-
// `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,
|
|
622
|
-
// )
|
|
623
|
-
// },
|
|
632
|
+
generate = options => {
|
|
633
|
+
invariant(false, `route.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `);
|
|
634
|
+
};
|
|
624
635
|
}
|
|
625
|
-
|
|
626
636
|
class RootRoute extends Route {
|
|
627
637
|
constructor(options) {
|
|
628
638
|
super(options);
|
|
@@ -676,8 +686,6 @@
|
|
|
676
686
|
// const config = rootRoute.addChildren([aRoute.addChildren([bRoute])])
|
|
677
687
|
// // ^?
|
|
678
688
|
|
|
679
|
-
//
|
|
680
|
-
|
|
681
689
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
682
690
|
class RouteMatch {
|
|
683
691
|
abortController = new AbortController();
|
|
@@ -711,40 +719,42 @@
|
|
|
711
719
|
#hasLoaders = () => {
|
|
712
720
|
return !!(this.route.options.onLoad || componentTypes.some(d => this.route.options[d]?.preload));
|
|
713
721
|
};
|
|
714
|
-
|
|
722
|
+
__commit = () => {
|
|
723
|
+
const {
|
|
724
|
+
routeSearch,
|
|
725
|
+
search,
|
|
726
|
+
context,
|
|
727
|
+
routeContext
|
|
728
|
+
} = this.#resolveInfo({
|
|
729
|
+
location: this.router.state.currentLocation
|
|
730
|
+
});
|
|
731
|
+
this.context = context;
|
|
732
|
+
this.routeContext = routeContext;
|
|
733
|
+
this.store.setState(s => ({
|
|
734
|
+
...s,
|
|
735
|
+
routeSearch: replaceEqualDeep(s.routeSearch, routeSearch),
|
|
736
|
+
search: replaceEqualDeep(s.search, search)
|
|
737
|
+
}));
|
|
738
|
+
};
|
|
739
|
+
cancel = () => {
|
|
740
|
+
this.abortController?.abort();
|
|
741
|
+
};
|
|
742
|
+
#resolveSearchInfo = opts => {
|
|
715
743
|
// Validate the search params and stabilize them
|
|
716
|
-
this.parentMatch
|
|
717
|
-
|
|
744
|
+
const parentSearchInfo = this.parentMatch ? this.parentMatch.#resolveSearchInfo(opts) : {
|
|
745
|
+
search: opts.location.search,
|
|
746
|
+
routeSearch: opts.location.search
|
|
747
|
+
};
|
|
718
748
|
try {
|
|
719
749
|
const validator = typeof this.route.options.validateSearch === 'object' ? this.route.options.validateSearch.parse : this.route.options.validateSearch;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
...
|
|
723
|
-
routeSearch
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}));
|
|
729
|
-
componentTypes.map(async type => {
|
|
730
|
-
const component = this.route.options[type];
|
|
731
|
-
if (typeof this[type] !== 'function') {
|
|
732
|
-
this[type] = component;
|
|
733
|
-
}
|
|
734
|
-
});
|
|
735
|
-
const parent = this.parentMatch;
|
|
736
|
-
this.routeContext = this.route.options.getContext?.({
|
|
737
|
-
parentContext: parent?.routeContext,
|
|
738
|
-
context: parent?.context,
|
|
739
|
-
params: this.params,
|
|
740
|
-
search: this.state.search
|
|
741
|
-
}) || {};
|
|
742
|
-
this.context = parent ? {
|
|
743
|
-
...parent.context,
|
|
744
|
-
...this.routeContext
|
|
745
|
-
} : {
|
|
746
|
-
...this.router?.options.context,
|
|
747
|
-
...this.routeContext
|
|
750
|
+
const routeSearch = validator?.(parentSearchInfo.search) ?? {};
|
|
751
|
+
const search = {
|
|
752
|
+
...parentSearchInfo.search,
|
|
753
|
+
...routeSearch
|
|
754
|
+
};
|
|
755
|
+
return {
|
|
756
|
+
routeSearch,
|
|
757
|
+
search
|
|
748
758
|
};
|
|
749
759
|
} catch (err) {
|
|
750
760
|
console.error(err);
|
|
@@ -752,27 +762,65 @@
|
|
|
752
762
|
cause: err
|
|
753
763
|
});
|
|
754
764
|
error.code = 'INVALID_SEARCH_PARAMS';
|
|
765
|
+
throw error;
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
#resolveInfo = opts => {
|
|
769
|
+
const {
|
|
770
|
+
search,
|
|
771
|
+
routeSearch
|
|
772
|
+
} = this.#resolveSearchInfo(opts);
|
|
773
|
+
const routeContext = this.route.options.getContext?.({
|
|
774
|
+
parentContext: this.parentMatch?.routeContext ?? {},
|
|
775
|
+
context: this.parentMatch?.context ?? this.router?.options.context ?? {},
|
|
776
|
+
params: this.params,
|
|
777
|
+
search
|
|
778
|
+
}) || {};
|
|
779
|
+
const context = {
|
|
780
|
+
...(this.parentMatch?.context ?? this.router?.options.context),
|
|
781
|
+
...routeContext
|
|
782
|
+
};
|
|
783
|
+
return {
|
|
784
|
+
routeSearch,
|
|
785
|
+
search,
|
|
786
|
+
context,
|
|
787
|
+
routeContext
|
|
788
|
+
};
|
|
789
|
+
};
|
|
790
|
+
__load = async opts => {
|
|
791
|
+
this.parentMatch = opts.parentMatch;
|
|
792
|
+
let info;
|
|
793
|
+
try {
|
|
794
|
+
info = this.#resolveInfo(opts);
|
|
795
|
+
} catch (err) {
|
|
755
796
|
this.store.setState(s => ({
|
|
756
797
|
...s,
|
|
757
798
|
status: 'error',
|
|
758
|
-
error:
|
|
799
|
+
error: err
|
|
759
800
|
}));
|
|
760
801
|
|
|
761
802
|
// Do not proceed with loading the route
|
|
762
803
|
return;
|
|
763
804
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
805
|
+
const {
|
|
806
|
+
routeSearch,
|
|
807
|
+
search,
|
|
808
|
+
context,
|
|
809
|
+
routeContext
|
|
810
|
+
} = info;
|
|
811
|
+
componentTypes.map(async type => {
|
|
812
|
+
const component = this.route.options[type];
|
|
813
|
+
if (typeof this[type] !== 'function') {
|
|
814
|
+
this[type] = component;
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
|
|
769
818
|
// If the match is invalid, errored or idle, trigger it to load
|
|
770
|
-
if (this.state.status
|
|
771
|
-
|
|
819
|
+
if (this.state.status === 'pending') {
|
|
820
|
+
return;
|
|
772
821
|
}
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
fetch = async opts => {
|
|
822
|
+
|
|
823
|
+
// TODO: Should load promises be tracked based on location?
|
|
776
824
|
this.__loadPromise = Promise.resolve().then(async () => {
|
|
777
825
|
const loadId = '' + Date.now() + Math.random();
|
|
778
826
|
this.#latestId = loadId;
|
|
@@ -780,17 +828,16 @@
|
|
|
780
828
|
return loadId !== this.#latestId ? this.__loadPromise : undefined;
|
|
781
829
|
};
|
|
782
830
|
let latestPromise;
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
});
|
|
831
|
+
|
|
832
|
+
// If the match was in an error state, set it
|
|
833
|
+
// to a loading state again. Otherwise, keep it
|
|
834
|
+
// as loading or resolved
|
|
835
|
+
if (this.state.status === 'idle') {
|
|
836
|
+
this.store.setState(s => ({
|
|
837
|
+
...s,
|
|
838
|
+
status: 'pending'
|
|
839
|
+
}));
|
|
840
|
+
}
|
|
794
841
|
const componentsPromise = (async () => {
|
|
795
842
|
// then run all component and data loaders in parallel
|
|
796
843
|
// For each component type, potentially load it asynchronously
|
|
@@ -806,11 +853,12 @@
|
|
|
806
853
|
if (this.route.options.onLoad) {
|
|
807
854
|
return this.route.options.onLoad({
|
|
808
855
|
params: this.params,
|
|
809
|
-
|
|
856
|
+
routeSearch,
|
|
857
|
+
search,
|
|
810
858
|
signal: this.abortController.signal,
|
|
811
859
|
preload: !!opts?.preload,
|
|
812
|
-
routeContext:
|
|
813
|
-
context:
|
|
860
|
+
routeContext: routeContext,
|
|
861
|
+
context: context
|
|
814
862
|
});
|
|
815
863
|
}
|
|
816
864
|
return;
|
|
@@ -838,6 +886,7 @@
|
|
|
838
886
|
});
|
|
839
887
|
return this.__loadPromise;
|
|
840
888
|
};
|
|
889
|
+
#latestId = '';
|
|
841
890
|
}
|
|
842
891
|
|
|
843
892
|
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
@@ -1043,7 +1092,7 @@
|
|
|
1043
1092
|
|
|
1044
1093
|
// Load the matches
|
|
1045
1094
|
try {
|
|
1046
|
-
await this.loadMatches(matches
|
|
1095
|
+
await this.loadMatches(matches, this.state.pendingLocation
|
|
1047
1096
|
// opts
|
|
1048
1097
|
);
|
|
1049
1098
|
} catch (err) {
|
|
@@ -1095,6 +1144,7 @@
|
|
|
1095
1144
|
search: d.state.search
|
|
1096
1145
|
});
|
|
1097
1146
|
});
|
|
1147
|
+
const prevLocation = this.state.currentLocation;
|
|
1098
1148
|
this.store.setState(s => ({
|
|
1099
1149
|
...s,
|
|
1100
1150
|
status: 'idle',
|
|
@@ -1103,7 +1153,12 @@
|
|
|
1103
1153
|
pendingLocation: undefined,
|
|
1104
1154
|
pendingMatches: undefined
|
|
1105
1155
|
}));
|
|
1106
|
-
|
|
1156
|
+
matches.forEach(match => {
|
|
1157
|
+
match.__commit();
|
|
1158
|
+
});
|
|
1159
|
+
if (prevLocation.href !== this.state.currentLocation.href) {
|
|
1160
|
+
this.options.onRouteChange?.();
|
|
1161
|
+
}
|
|
1107
1162
|
this.resolveNavigation();
|
|
1108
1163
|
};
|
|
1109
1164
|
getRoute = id => {
|
|
@@ -1116,7 +1171,7 @@
|
|
|
1116
1171
|
const matches = this.matchRoutes(next.pathname, {
|
|
1117
1172
|
strictParseParams: true
|
|
1118
1173
|
});
|
|
1119
|
-
await this.loadMatches(matches);
|
|
1174
|
+
await this.loadMatches(matches, next);
|
|
1120
1175
|
return matches;
|
|
1121
1176
|
};
|
|
1122
1177
|
preloadRoute = async (navigateOpts = this.state.latestLocation) => {
|
|
@@ -1124,7 +1179,7 @@
|
|
|
1124
1179
|
const matches = this.matchRoutes(next.pathname, {
|
|
1125
1180
|
strictParseParams: true
|
|
1126
1181
|
});
|
|
1127
|
-
await this.loadMatches(matches, {
|
|
1182
|
+
await this.loadMatches(matches, next, {
|
|
1128
1183
|
preload: true
|
|
1129
1184
|
});
|
|
1130
1185
|
return matches;
|
|
@@ -1196,9 +1251,7 @@
|
|
|
1196
1251
|
findInRouteTree([this.routeTree]);
|
|
1197
1252
|
return matches;
|
|
1198
1253
|
};
|
|
1199
|
-
loadMatches = async (resolvedMatches, opts) => {
|
|
1200
|
-
initMatches(resolvedMatches);
|
|
1201
|
-
|
|
1254
|
+
loadMatches = async (resolvedMatches, location, opts) => {
|
|
1202
1255
|
// Check each match middleware to see if the route can be accessed
|
|
1203
1256
|
await Promise.all(resolvedMatches.map(async match => {
|
|
1204
1257
|
try {
|
|
@@ -1214,22 +1267,15 @@
|
|
|
1214
1267
|
}
|
|
1215
1268
|
}));
|
|
1216
1269
|
const matchPromises = resolvedMatches.map(async (match, index) => {
|
|
1217
|
-
const
|
|
1218
|
-
match.
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
// }
|
|
1223
|
-
|
|
1224
|
-
match.load({
|
|
1225
|
-
preload: opts?.preload
|
|
1270
|
+
const parentMatch = resolvedMatches[index - 1];
|
|
1271
|
+
match.__load({
|
|
1272
|
+
preload: opts?.preload,
|
|
1273
|
+
location,
|
|
1274
|
+
parentMatch
|
|
1226
1275
|
});
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
await
|
|
1230
|
-
}
|
|
1231
|
-
if (prevMatch) {
|
|
1232
|
-
await prevMatch.__loadPromise;
|
|
1276
|
+
await match.__loadPromise;
|
|
1277
|
+
if (parentMatch) {
|
|
1278
|
+
await parentMatch.__loadPromise;
|
|
1233
1279
|
}
|
|
1234
1280
|
});
|
|
1235
1281
|
await Promise.all(matchPromises);
|
|
@@ -1246,7 +1292,7 @@
|
|
|
1246
1292
|
};
|
|
1247
1293
|
navigate = async ({
|
|
1248
1294
|
from,
|
|
1249
|
-
to = '
|
|
1295
|
+
to = '',
|
|
1250
1296
|
search,
|
|
1251
1297
|
hash,
|
|
1252
1298
|
replace,
|
|
@@ -1280,19 +1326,21 @@
|
|
|
1280
1326
|
to: location.to ? this.resolvePath(location.from ?? '', location.to) : undefined
|
|
1281
1327
|
};
|
|
1282
1328
|
const next = this.buildNext(location);
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
}
|
|
1287
|
-
return matchPathname(this.basepath, this.state.pendingLocation.pathname, {
|
|
1288
|
-
...opts,
|
|
1289
|
-
to: next.pathname
|
|
1290
|
-
});
|
|
1329
|
+
const baseLocation = opts?.pending ? this.state.pendingLocation : this.state.currentLocation;
|
|
1330
|
+
if (!baseLocation) {
|
|
1331
|
+
return false;
|
|
1291
1332
|
}
|
|
1292
|
-
|
|
1333
|
+
const match = matchPathname(this.basepath, baseLocation.pathname, {
|
|
1293
1334
|
...opts,
|
|
1294
1335
|
to: next.pathname
|
|
1295
1336
|
});
|
|
1337
|
+
if (!match) {
|
|
1338
|
+
return false;
|
|
1339
|
+
}
|
|
1340
|
+
if (opts?.includeSearch ?? true) {
|
|
1341
|
+
return partialDeepEqual(baseLocation.search, next.search) ? match : false;
|
|
1342
|
+
}
|
|
1343
|
+
return match;
|
|
1296
1344
|
};
|
|
1297
1345
|
buildLink = ({
|
|
1298
1346
|
from,
|
|
@@ -1304,8 +1352,6 @@
|
|
|
1304
1352
|
replace,
|
|
1305
1353
|
activeOptions,
|
|
1306
1354
|
preload,
|
|
1307
|
-
preloadMaxAge: userPreloadMaxAge,
|
|
1308
|
-
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
1309
1355
|
preloadDelay: userPreloadDelay,
|
|
1310
1356
|
disabled
|
|
1311
1357
|
}) => {
|
|
@@ -1335,17 +1381,16 @@
|
|
|
1335
1381
|
const preloadDelay = userPreloadDelay ?? this.options.defaultPreloadDelay ?? 0;
|
|
1336
1382
|
|
|
1337
1383
|
// Compare path/hash for matches
|
|
1338
|
-
const pathIsEqual = this.state.currentLocation.pathname === next.pathname;
|
|
1339
1384
|
const currentPathSplit = this.state.currentLocation.pathname.split('/');
|
|
1340
1385
|
const nextPathSplit = next.pathname.split('/');
|
|
1341
1386
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
1342
|
-
const hashIsEqual = this.state.currentLocation.hash === next.hash;
|
|
1343
1387
|
// Combine the matches based on user options
|
|
1344
|
-
const pathTest = activeOptions?.exact ?
|
|
1345
|
-
const hashTest = activeOptions?.includeHash ?
|
|
1388
|
+
const pathTest = activeOptions?.exact ? this.state.currentLocation.pathname === next.pathname : pathIsFuzzyEqual;
|
|
1389
|
+
const hashTest = activeOptions?.includeHash ? this.state.currentLocation.hash === next.hash : true;
|
|
1390
|
+
const searchTest = activeOptions?.includeSearch ?? true ? partialDeepEqual(this.state.currentLocation.search, next.search) : true;
|
|
1346
1391
|
|
|
1347
1392
|
// The final "active" test
|
|
1348
|
-
const isActive = pathTest && hashTest;
|
|
1393
|
+
const isActive = pathTest && hashTest && searchTest;
|
|
1349
1394
|
|
|
1350
1395
|
// The click handler
|
|
1351
1396
|
const handleClick = e => {
|
|
@@ -1426,7 +1471,6 @@
|
|
|
1426
1471
|
...dehydratedMatch.state
|
|
1427
1472
|
}));
|
|
1428
1473
|
});
|
|
1429
|
-
initMatches(currentMatches);
|
|
1430
1474
|
return {
|
|
1431
1475
|
...s,
|
|
1432
1476
|
...dehydratedRouter.state,
|
|
@@ -1478,8 +1522,9 @@
|
|
|
1478
1522
|
this.load();
|
|
1479
1523
|
};
|
|
1480
1524
|
#buildLocation = (dest = {}) => {
|
|
1525
|
+
dest.fromCurrent = dest.fromCurrent ?? dest.to === '';
|
|
1481
1526
|
const fromPathname = dest.fromCurrent ? this.state.latestLocation.pathname : dest.from ?? this.state.latestLocation.pathname;
|
|
1482
|
-
let pathname = resolvePath(this.basepath ?? '/', fromPathname, `${dest.to ?? '
|
|
1527
|
+
let pathname = resolvePath(this.basepath ?? '/', fromPathname, `${dest.to ?? ''}`);
|
|
1483
1528
|
const fromMatches = this.matchRoutes(this.state.latestLocation.pathname, {
|
|
1484
1529
|
strictParseParams: true
|
|
1485
1530
|
});
|
|
@@ -1564,14 +1609,6 @@
|
|
|
1564
1609
|
function isCtrlEvent(e) {
|
|
1565
1610
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
1566
1611
|
}
|
|
1567
|
-
function initMatches(matches) {
|
|
1568
|
-
matches.forEach((match, index) => {
|
|
1569
|
-
const parentMatch = matches[index - 1];
|
|
1570
|
-
match.__init({
|
|
1571
|
-
parentMatch
|
|
1572
|
-
});
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
1612
|
|
|
1576
1613
|
/**
|
|
1577
1614
|
* react-store
|
|
@@ -1664,7 +1701,6 @@
|
|
|
1664
1701
|
to = '.',
|
|
1665
1702
|
preload,
|
|
1666
1703
|
preloadDelay,
|
|
1667
|
-
preloadMaxAge,
|
|
1668
1704
|
replace,
|
|
1669
1705
|
// element props
|
|
1670
1706
|
style,
|
|
@@ -2042,6 +2078,7 @@
|
|
|
2042
2078
|
exports.matchesContext = matchesContext;
|
|
2043
2079
|
exports.parsePathname = parsePathname;
|
|
2044
2080
|
exports.parseSearchWith = parseSearchWith;
|
|
2081
|
+
exports.partialDeepEqual = partialDeepEqual;
|
|
2045
2082
|
exports.pick = pick;
|
|
2046
2083
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2047
2084
|
exports.resolvePath = resolvePath;
|