@ionic/react-router 8.8.1-dev.11773873479.192398dc → 8.8.1-dev.11773929121.1aabdf46
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/index.js +577 -2948
- package/dist/index.js.map +1 -1
- package/dist/types/ReactRouter/IonReactHashRouter.d.ts +22 -7
- package/dist/types/ReactRouter/IonReactMemoryRouter.d.ts +21 -7
- package/dist/types/ReactRouter/IonReactRouter.d.ts +21 -8
- package/dist/types/ReactRouter/IonRouteInner.d.ts +3 -1
- package/dist/types/ReactRouter/IonRouter.d.ts +38 -18
- package/dist/types/ReactRouter/ReactRouterViewStack.d.ts +6 -75
- package/dist/types/ReactRouter/StackManager.d.ts +30 -0
- package/dist/types/ReactRouter/utils/matchPath.d.ts +21 -0
- package/package.json +8 -7
- package/dist/types/ReactRouter/utils/computeParentPath.d.ts +0 -61
- package/dist/types/ReactRouter/utils/pathMatching.d.ts +0 -31
- package/dist/types/ReactRouter/utils/pathNormalization.d.ts +0 -22
- package/dist/types/ReactRouter/utils/routeElements.d.ts +0 -23
- package/dist/types/ReactRouter/utils/viewItemUtils.d.ts +0 -30
package/dist/index.js
CHANGED
|
@@ -1,1301 +1,176 @@
|
|
|
1
1
|
import { __rest } from 'tslib';
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { createBrowserHistory, createHashHistory } from 'history';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { withRouter, Router } from 'react-router-dom';
|
|
5
|
+
import { ViewStacks, generateId, IonRoute, ViewLifeCycleManager, StackContext, RouteManagerContext, getConfig, LocationHistory, NavManager } from '@ionic/react';
|
|
6
|
+
import { Route, matchPath as matchPath$1, Router as Router$1 } from 'react-router';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
* The matchPath function is used only for matching paths, not rendering components or elements.
|
|
13
|
-
* @see https://reactrouter.com/v6/utils/match-path
|
|
14
|
-
*/
|
|
15
|
-
const matchPath = ({ pathname, componentProps }) => {
|
|
16
|
-
var _a, _b;
|
|
17
|
-
const { path, index } = componentProps, restProps = __rest(componentProps, ["path", "index"]);
|
|
18
|
-
// Handle index routes - they match when pathname is empty or just "/"
|
|
19
|
-
if (index && !path) {
|
|
20
|
-
if (pathname === '' || pathname === '/') {
|
|
21
|
-
return {
|
|
22
|
-
params: {},
|
|
23
|
-
pathname: pathname,
|
|
24
|
-
pathnameBase: pathname || '/',
|
|
25
|
-
pattern: {
|
|
26
|
-
path: '',
|
|
27
|
-
caseSensitive: false,
|
|
28
|
-
end: true,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
// Handle empty path routes - they match when pathname is also empty or just "/"
|
|
35
|
-
if (path === '' || path === undefined) {
|
|
36
|
-
if (pathname === '' || pathname === '/') {
|
|
37
|
-
return {
|
|
38
|
-
params: {},
|
|
39
|
-
pathname: pathname,
|
|
40
|
-
pathnameBase: pathname || '/',
|
|
41
|
-
pattern: {
|
|
42
|
-
path: '',
|
|
43
|
-
caseSensitive: (_a = restProps.caseSensitive) !== null && _a !== void 0 ? _a : false,
|
|
44
|
-
end: (_b = restProps.end) !== null && _b !== void 0 ? _b : true,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
// For relative paths (don't start with '/'), normalize both path and pathname for matching
|
|
51
|
-
if (!path.startsWith('/')) {
|
|
52
|
-
const matchOptions = Object.assign({ path: `/${path}` }, restProps);
|
|
53
|
-
if ((matchOptions === null || matchOptions === void 0 ? void 0 : matchOptions.end) === undefined) {
|
|
54
|
-
matchOptions.end = !path.endsWith('*');
|
|
55
|
-
}
|
|
56
|
-
const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
|
|
57
|
-
const match = matchPath$1(matchOptions, normalizedPathname);
|
|
58
|
-
if (match) {
|
|
59
|
-
// Adjust the match to remove the leading '/' we added
|
|
60
|
-
return Object.assign(Object.assign({}, match), { pathname: pathname, pathnameBase: match.pathnameBase === '/' ? '/' : match.pathnameBase.slice(1), pattern: Object.assign(Object.assign({}, match.pattern), { path: path }) });
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
// For absolute paths, use React Router's matcher directly.
|
|
65
|
-
// React Router v6 routes default to `end: true` unless the pattern
|
|
66
|
-
// explicitly opts into wildcards with `*`. Mirror that behaviour so
|
|
67
|
-
// matching parity stays aligned with <Route>.
|
|
68
|
-
const matchOptions = Object.assign({ path }, restProps);
|
|
69
|
-
if ((matchOptions === null || matchOptions === void 0 ? void 0 : matchOptions.end) === undefined) {
|
|
70
|
-
matchOptions.end = !path.endsWith('*');
|
|
71
|
-
}
|
|
72
|
-
return matchPath$1(matchOptions, pathname);
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Determines the portion of a pathname that a given route pattern should match against.
|
|
76
|
-
* For absolute route patterns we return the full pathname. For relative patterns we
|
|
77
|
-
* strip off the already-matched parent segments so React Router receives the remainder.
|
|
78
|
-
*/
|
|
79
|
-
const derivePathnameToMatch = (fullPathname, routePath) => {
|
|
80
|
-
var _a;
|
|
81
|
-
// For absolute or empty routes, use the full pathname as-is
|
|
82
|
-
if (!routePath || routePath === '' || routePath.startsWith('/')) {
|
|
83
|
-
return fullPathname;
|
|
84
|
-
}
|
|
85
|
-
const trimmedPath = fullPathname.startsWith('/') ? fullPathname.slice(1) : fullPathname;
|
|
86
|
-
if (!trimmedPath) {
|
|
87
|
-
// For root-level relative routes (pathname is "/" and routePath is relative),
|
|
88
|
-
// return the full pathname so matchPath can normalize both.
|
|
89
|
-
// This allows routes like <Route path="foo/*" .../> at root level to work correctly.
|
|
90
|
-
return fullPathname;
|
|
91
|
-
}
|
|
92
|
-
const fullSegments = trimmedPath.split('/').filter(Boolean);
|
|
93
|
-
if (fullSegments.length === 0) {
|
|
94
|
-
return '';
|
|
95
|
-
}
|
|
96
|
-
const routeSegments = routePath.split('/').filter(Boolean);
|
|
97
|
-
if (routeSegments.length === 0) {
|
|
98
|
-
return trimmedPath;
|
|
99
|
-
}
|
|
100
|
-
const wildcardIndex = routeSegments.findIndex((segment) => segment === '*' || segment === '**');
|
|
101
|
-
if (wildcardIndex >= 0) {
|
|
102
|
-
const baseSegments = routeSegments.slice(0, wildcardIndex);
|
|
103
|
-
if (baseSegments.length === 0) {
|
|
104
|
-
return trimmedPath;
|
|
105
|
-
}
|
|
106
|
-
const startIndex = fullSegments.findIndex((_, idx) => baseSegments.every((seg, segIdx) => {
|
|
107
|
-
const target = fullSegments[idx + segIdx];
|
|
108
|
-
if (!target) {
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
if (seg.startsWith(':')) {
|
|
112
|
-
return true;
|
|
8
|
+
class IonRouteInner extends React.PureComponent {
|
|
9
|
+
render() {
|
|
10
|
+
return (React.createElement(Route, Object.assign({ path: this.props.path, exact: this.props.exact, render: this.props.render }, (this.props.computedMatch !== undefined
|
|
11
|
+
? {
|
|
12
|
+
computedMatch: this.props.computedMatch,
|
|
113
13
|
}
|
|
114
|
-
|
|
115
|
-
}));
|
|
116
|
-
if (startIndex >= 0) {
|
|
117
|
-
return fullSegments.slice(startIndex).join('/');
|
|
118
|
-
}
|
|
14
|
+
: {}))));
|
|
119
15
|
}
|
|
120
|
-
|
|
121
|
-
return fullSegments.slice(fullSegments.length - routeSegments.length).join('/');
|
|
122
|
-
}
|
|
123
|
-
return (_a = fullSegments[fullSegments.length - 1]) !== null && _a !== void 0 ? _a : trimmedPath;
|
|
124
|
-
};
|
|
16
|
+
}
|
|
125
17
|
|
|
126
18
|
/**
|
|
127
|
-
*
|
|
128
|
-
* Used to determine the scope of an outlet with absolute routes.
|
|
129
|
-
*
|
|
130
|
-
* @param paths An array of absolute path strings.
|
|
131
|
-
* @returns The common prefix shared by all paths.
|
|
132
|
-
*/
|
|
133
|
-
const computeCommonPrefix = (paths) => {
|
|
134
|
-
if (paths.length === 0)
|
|
135
|
-
return '';
|
|
136
|
-
if (paths.length === 1) {
|
|
137
|
-
// For a single path, extract the directory-like prefix
|
|
138
|
-
// e.g., /dynamic-routes/home -> /dynamic-routes
|
|
139
|
-
const segments = paths[0].split('/').filter(Boolean);
|
|
140
|
-
if (segments.length > 1) {
|
|
141
|
-
return '/' + segments.slice(0, -1).join('/');
|
|
142
|
-
}
|
|
143
|
-
return '/' + segments[0];
|
|
144
|
-
}
|
|
145
|
-
// Split all paths into segments
|
|
146
|
-
const segmentArrays = paths.map((p) => p.split('/').filter(Boolean));
|
|
147
|
-
const minLength = Math.min(...segmentArrays.map((s) => s.length));
|
|
148
|
-
const commonSegments = [];
|
|
149
|
-
for (let i = 0; i < minLength; i++) {
|
|
150
|
-
const segment = segmentArrays[0][i];
|
|
151
|
-
// Skip segments with route parameters or wildcards
|
|
152
|
-
if (segment.includes(':') || segment.includes('*')) {
|
|
153
|
-
break;
|
|
154
|
-
}
|
|
155
|
-
const allMatch = segmentArrays.every((s) => s[i] === segment);
|
|
156
|
-
if (allMatch) {
|
|
157
|
-
commonSegments.push(segment);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return commonSegments.length > 0 ? '/' + commonSegments.join('/') : '';
|
|
164
|
-
};
|
|
165
|
-
/**
|
|
166
|
-
* Checks if a pathname falls within the scope of a mount path using
|
|
167
|
-
* segment-aware comparison. Prevents false positives like "/tabs-secondary"
|
|
168
|
-
* matching mount path "/tabs".
|
|
19
|
+
* @see https://v5.reactrouter.com/web/api/matchPath
|
|
169
20
|
*/
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return !!routePath && routePath.includes('*') && !isSplatOnlyRoute(routePath);
|
|
186
|
-
};
|
|
187
|
-
/**
|
|
188
|
-
* Checks if a route with an embedded wildcard matches a pathname.
|
|
189
|
-
*/
|
|
190
|
-
const matchesEmbeddedWildcardRoute = (route, pathname) => {
|
|
191
|
-
const routePath = route.props.path;
|
|
192
|
-
if (!hasEmbeddedWildcard(routePath)) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
return !!matchPath({ pathname, componentProps: route.props });
|
|
196
|
-
};
|
|
197
|
-
/**
|
|
198
|
-
* Checks if a route is a specific match (not wildcard-only or index).
|
|
199
|
-
*/
|
|
200
|
-
const isSpecificRouteMatch = (route, remainingPath) => {
|
|
201
|
-
const routePath = route.props.path;
|
|
202
|
-
if (route.props.index || isSplatOnlyRoute(routePath)) {
|
|
21
|
+
const matchPath = ({ pathname, componentProps, }) => {
|
|
22
|
+
const { exact, component } = componentProps;
|
|
23
|
+
const path = componentProps.path || componentProps.from;
|
|
24
|
+
/***
|
|
25
|
+
* The props to match against, they are identical
|
|
26
|
+
* to the matching props `Route` accepts. It could also be a string
|
|
27
|
+
* or an array of strings as shortcut for `{ path }`.
|
|
28
|
+
*/
|
|
29
|
+
const matchProps = {
|
|
30
|
+
exact,
|
|
31
|
+
path,
|
|
32
|
+
component,
|
|
33
|
+
};
|
|
34
|
+
const match = matchPath$1(pathname, matchProps);
|
|
35
|
+
if (!match) {
|
|
203
36
|
return false;
|
|
204
37
|
}
|
|
205
|
-
return
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Analyzes route children to determine their characteristics.
|
|
209
|
-
*
|
|
210
|
-
* @param routeChildren The route children to analyze.
|
|
211
|
-
* @returns Analysis of the route characteristics.
|
|
212
|
-
*/
|
|
213
|
-
const analyzeRouteChildren = (routeChildren) => {
|
|
214
|
-
const hasRelativeRoutes = routeChildren.some((route) => {
|
|
215
|
-
const path = route.props.path;
|
|
216
|
-
return path && !path.startsWith('/') && path !== '*';
|
|
217
|
-
});
|
|
218
|
-
const hasIndexRoute = routeChildren.some((route) => route.props.index);
|
|
219
|
-
const hasWildcardRoute = routeChildren.some((route) => {
|
|
220
|
-
const routePath = route.props.path;
|
|
221
|
-
return routePath === '*' || routePath === '/*';
|
|
222
|
-
});
|
|
223
|
-
return { hasRelativeRoutes, hasIndexRoute, hasWildcardRoute, routeChildren };
|
|
224
|
-
};
|
|
225
|
-
/**
|
|
226
|
-
* Checks if any route matches as a specific (non-wildcard, non-index) route.
|
|
227
|
-
*/
|
|
228
|
-
const findSpecificMatch = (routeChildren, remainingPath) => {
|
|
229
|
-
return routeChildren.some((route) => isSpecificRouteMatch(route, remainingPath) || matchesEmbeddedWildcardRoute(route, remainingPath));
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Returns the first route that matches as a specific (non-wildcard, non-index) route.
|
|
233
|
-
*/
|
|
234
|
-
const findFirstSpecificMatchingRoute = (routeChildren, remainingPath) => {
|
|
235
|
-
return routeChildren.find((route) => isSpecificRouteMatch(route, remainingPath) || matchesEmbeddedWildcardRoute(route, remainingPath));
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Checks if any specific route could plausibly match the remaining path.
|
|
239
|
-
* Used to determine if we should fall back to a wildcard match.
|
|
240
|
-
*
|
|
241
|
-
* Uses exact first-segment matching: the remaining path's first segment
|
|
242
|
-
* must exactly equal a route's first segment to block the wildcard.
|
|
243
|
-
* The outlet's mount path is always known from React Router's RouteContext,
|
|
244
|
-
* so no heuristic-based discovery is needed.
|
|
245
|
-
*/
|
|
246
|
-
const couldSpecificRouteMatch = (routeChildren, remainingPath) => {
|
|
247
|
-
const remainingFirstSegment = remainingPath.split('/')[0];
|
|
248
|
-
return routeChildren.some((route) => {
|
|
249
|
-
const routePath = route.props.path;
|
|
250
|
-
if (!routePath || routePath === '*' || routePath === '/*')
|
|
251
|
-
return false;
|
|
252
|
-
if (route.props.index)
|
|
253
|
-
return false;
|
|
254
|
-
const routeFirstSegment = routePath.split('/')[0].replace(/[*:]/g, '');
|
|
255
|
-
if (!routeFirstSegment)
|
|
256
|
-
return false;
|
|
257
|
-
return routeFirstSegment === remainingFirstSegment;
|
|
258
|
-
});
|
|
259
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* Determines the best parent path from the available matches.
|
|
262
|
-
* Priority: specific > wildcard > index
|
|
263
|
-
*/
|
|
264
|
-
const selectBestMatch = (specificMatch, wildcardMatch, indexMatch) => {
|
|
265
|
-
var _a;
|
|
266
|
-
return (_a = specificMatch !== null && specificMatch !== void 0 ? specificMatch : wildcardMatch) !== null && _a !== void 0 ? _a : indexMatch;
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* Handles outlets with only absolute routes by computing their common prefix.
|
|
270
|
-
*/
|
|
271
|
-
const computeAbsoluteRoutesParentPath = (routeChildren, currentPathname, outletMountPath) => {
|
|
272
|
-
const absolutePathRoutes = routeChildren.filter((route) => {
|
|
273
|
-
const path = route.props.path;
|
|
274
|
-
return path && path.startsWith('/');
|
|
275
|
-
});
|
|
276
|
-
if (absolutePathRoutes.length === 0) {
|
|
277
|
-
return undefined;
|
|
278
|
-
}
|
|
279
|
-
const absolutePaths = absolutePathRoutes.map((r) => r.props.path);
|
|
280
|
-
const commonPrefix = computeCommonPrefix(absolutePaths);
|
|
281
|
-
if (!commonPrefix || commonPrefix === '/') {
|
|
282
|
-
return undefined;
|
|
283
|
-
}
|
|
284
|
-
const newOutletMountPath = outletMountPath || commonPrefix;
|
|
285
|
-
if (!currentPathname.startsWith(commonPrefix)) {
|
|
286
|
-
return { parentPath: undefined, outletMountPath: newOutletMountPath };
|
|
287
|
-
}
|
|
288
|
-
return { parentPath: commonPrefix, outletMountPath: newOutletMountPath };
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Computes the parent path for a nested outlet based on the current pathname
|
|
292
|
-
* and the outlet's route configuration.
|
|
293
|
-
*
|
|
294
|
-
* When the mount path is known (seeded from React Router's RouteContext), the
|
|
295
|
-
* parent path is simply the mount path — no iterative discovery needed. The
|
|
296
|
-
* iterative fallback only runs for outlets where RouteContext doesn't provide
|
|
297
|
-
* a parent match (typically root-level outlets on first render).
|
|
298
|
-
*
|
|
299
|
-
* @param options The options for computing the parent path.
|
|
300
|
-
* @returns The computed parent path result.
|
|
301
|
-
*/
|
|
302
|
-
const computeParentPath = (options) => {
|
|
303
|
-
const { currentPathname, outletMountPath, routeChildren, hasRelativeRoutes, hasIndexRoute, hasWildcardRoute } = options;
|
|
304
|
-
// If pathname is outside the established mount path scope, skip computation.
|
|
305
|
-
// Use segment-aware comparison: /tabs-secondary must NOT match /tabs scope.
|
|
306
|
-
if (outletMountPath && !isPathnameInScope(currentPathname, outletMountPath)) {
|
|
307
|
-
return { parentPath: undefined, outletMountPath };
|
|
308
|
-
}
|
|
309
|
-
// Fast path: when the mount path is known (from React Router's RouteContext),
|
|
310
|
-
// the parent path IS the mount path. The iterative segment-by-segment discovery
|
|
311
|
-
// below was needed when the mount depth had to be guessed from URL structure,
|
|
312
|
-
// but with RouteContext we already know exactly where this outlet is mounted.
|
|
313
|
-
if (outletMountPath && (hasRelativeRoutes || hasIndexRoute)) {
|
|
314
|
-
return { parentPath: outletMountPath, outletMountPath };
|
|
315
|
-
}
|
|
316
|
-
// Fallback: mount path not yet known. Iterate through path segments to discover
|
|
317
|
-
// the correct parent depth. This only runs on first render of outlets where
|
|
318
|
-
// RouteContext doesn't provide a parent match (typically root-level outlets,
|
|
319
|
-
// which usually have absolute routes and take the absolute routes path below).
|
|
320
|
-
if (!outletMountPath && (hasRelativeRoutes || hasIndexRoute) && currentPathname.includes('/')) {
|
|
321
|
-
const segments = currentPathname.split('/').filter(Boolean);
|
|
322
|
-
if (segments.length >= 1) {
|
|
323
|
-
let firstSpecificMatch;
|
|
324
|
-
let firstWildcardMatch;
|
|
325
|
-
let indexMatchAtMount;
|
|
326
|
-
for (let i = 1; i <= segments.length; i++) {
|
|
327
|
-
const parentPath = '/' + segments.slice(0, i).join('/');
|
|
328
|
-
const remainingPath = segments.slice(i).join('/');
|
|
329
|
-
// Check for specific route match (highest priority)
|
|
330
|
-
if (!firstSpecificMatch && findSpecificMatch(routeChildren, remainingPath)) {
|
|
331
|
-
// Don't let empty/default path routes (path="" or undefined) drive
|
|
332
|
-
// the parent deeper than a wildcard match. An empty path route matching
|
|
333
|
-
// when remainingPath is "" just means all segments were consumed.
|
|
334
|
-
if (firstWildcardMatch) {
|
|
335
|
-
const matchingRoute = findFirstSpecificMatchingRoute(routeChildren, remainingPath);
|
|
336
|
-
if (matchingRoute) {
|
|
337
|
-
const matchingPath = matchingRoute.props.path;
|
|
338
|
-
if (!matchingPath || matchingPath === '') {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
firstSpecificMatch = parentPath;
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
// Check for wildcard match (only if remaining path is non-empty)
|
|
347
|
-
const hasNonEmptyRemaining = remainingPath !== '' && remainingPath !== '/';
|
|
348
|
-
if (!firstWildcardMatch && hasNonEmptyRemaining && hasWildcardRoute) {
|
|
349
|
-
if (!couldSpecificRouteMatch(routeChildren, remainingPath)) {
|
|
350
|
-
firstWildcardMatch = parentPath;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
// Check for index route match
|
|
354
|
-
if ((remainingPath === '' || remainingPath === '/') && hasIndexRoute) {
|
|
355
|
-
indexMatchAtMount = parentPath;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
// Fallback: check root level for embedded wildcard routes (e.g., "tab1/*")
|
|
359
|
-
if (!firstSpecificMatch) {
|
|
360
|
-
const fullRemainingPath = segments.join('/');
|
|
361
|
-
if (routeChildren.some((route) => matchesEmbeddedWildcardRoute(route, fullRemainingPath))) {
|
|
362
|
-
firstSpecificMatch = '/';
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
const bestPath = selectBestMatch(firstSpecificMatch, firstWildcardMatch, indexMatchAtMount);
|
|
366
|
-
return { parentPath: bestPath, outletMountPath: bestPath };
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
// Handle outlets with only absolute routes
|
|
370
|
-
if (!hasRelativeRoutes && !hasIndexRoute) {
|
|
371
|
-
const result = computeAbsoluteRoutesParentPath(routeChildren, currentPathname, outletMountPath);
|
|
372
|
-
if (result) {
|
|
373
|
-
return result;
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return { parentPath: outletMountPath, outletMountPath };
|
|
377
|
-
};
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Ensures the given path has a leading slash.
|
|
381
|
-
*
|
|
382
|
-
* @param value The path string to normalize.
|
|
383
|
-
* @returns The path with a leading slash.
|
|
384
|
-
*/
|
|
385
|
-
const ensureLeadingSlash = (value) => {
|
|
386
|
-
if (value === '') {
|
|
387
|
-
return '/';
|
|
388
|
-
}
|
|
389
|
-
return value.startsWith('/') ? value : `/${value}`;
|
|
390
|
-
};
|
|
391
|
-
/**
|
|
392
|
-
* Strips the trailing slash from a path, unless it's the root path.
|
|
393
|
-
*
|
|
394
|
-
* @param value The path string to normalize.
|
|
395
|
-
* @returns The path without a trailing slash.
|
|
396
|
-
*/
|
|
397
|
-
const stripTrailingSlash = (value) => {
|
|
398
|
-
return value.length > 1 && value.endsWith('/') ? value.slice(0, -1) : value;
|
|
399
|
-
};
|
|
400
|
-
/**
|
|
401
|
-
* Normalizes a pathname for comparison by ensuring a leading slash
|
|
402
|
-
* and removing trailing slashes.
|
|
403
|
-
*
|
|
404
|
-
* @param value The pathname to normalize, can be undefined.
|
|
405
|
-
* @returns A normalized pathname string.
|
|
406
|
-
*/
|
|
407
|
-
const normalizePathnameForComparison = (value) => {
|
|
408
|
-
if (!value || value === '') {
|
|
409
|
-
return '/';
|
|
410
|
-
}
|
|
411
|
-
const withLeadingSlash = ensureLeadingSlash(value);
|
|
412
|
-
return stripTrailingSlash(withLeadingSlash);
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
/**
|
|
416
|
-
* Extracts the children from a Routes wrapper component.
|
|
417
|
-
* The use of `<Routes />` is encouraged with React Router v6.
|
|
418
|
-
*
|
|
419
|
-
* @param node The React node to extract Routes children from.
|
|
420
|
-
* @returns The children of the Routes component, or undefined if not found.
|
|
421
|
-
*/
|
|
422
|
-
const getRoutesChildren = (node) => {
|
|
423
|
-
let routesNode;
|
|
424
|
-
React.Children.forEach(node, (child) => {
|
|
425
|
-
if (child.type === Routes) {
|
|
426
|
-
routesNode = child;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
429
|
-
if (routesNode) {
|
|
430
|
-
// The children of the `<Routes />` component are most likely
|
|
431
|
-
// (and should be) the `<Route />` components.
|
|
432
|
-
return routesNode.props.children;
|
|
433
|
-
}
|
|
434
|
-
return undefined;
|
|
435
|
-
};
|
|
436
|
-
/**
|
|
437
|
-
* Extracts Route children from a node (either directly or from a Routes wrapper).
|
|
438
|
-
*
|
|
439
|
-
* @param children The children to extract routes from.
|
|
440
|
-
* @returns An array of Route elements.
|
|
441
|
-
*/
|
|
442
|
-
const extractRouteChildren = (children) => {
|
|
443
|
-
var _a;
|
|
444
|
-
const routesChildren = (_a = getRoutesChildren(children)) !== null && _a !== void 0 ? _a : children;
|
|
445
|
-
return React.Children.toArray(routesChildren).filter((child) => React.isValidElement(child) && (child.type === Route || child.type === IonRoute));
|
|
446
|
-
};
|
|
447
|
-
/**
|
|
448
|
-
* Checks if a React element is a Navigate component (redirect).
|
|
449
|
-
*
|
|
450
|
-
* @param element The element to check.
|
|
451
|
-
* @returns True if the element is a Navigate component.
|
|
452
|
-
*/
|
|
453
|
-
const isNavigateElement = (element) => {
|
|
454
|
-
return (React.isValidElement(element) &&
|
|
455
|
-
(element.type === Navigate || (typeof element.type === 'function' && element.type.name === 'Navigate')));
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Compares two routes by specificity for sorting (most specific first).
|
|
460
|
-
*
|
|
461
|
-
* Sort order:
|
|
462
|
-
* 1. Index routes come first
|
|
463
|
-
* 2. Wildcard-only routes (* or /*) come last
|
|
464
|
-
* 3. Exact matches (no wildcards/params) before wildcard/param routes
|
|
465
|
-
* 4. Among routes with same status, longer paths are more specific
|
|
466
|
-
*/
|
|
467
|
-
const compareRouteSpecificity = (a, b) => {
|
|
468
|
-
// Index routes come first
|
|
469
|
-
if (a.index && !b.index)
|
|
470
|
-
return -1;
|
|
471
|
-
if (!a.index && b.index)
|
|
472
|
-
return 1;
|
|
473
|
-
// Wildcard-only routes (* or /*) should come last
|
|
474
|
-
const aIsWildcardOnly = a.path === '*' || a.path === '/*';
|
|
475
|
-
const bIsWildcardOnly = b.path === '*' || b.path === '/*';
|
|
476
|
-
if (!aIsWildcardOnly && bIsWildcardOnly)
|
|
477
|
-
return -1;
|
|
478
|
-
if (aIsWildcardOnly && !bIsWildcardOnly)
|
|
479
|
-
return 1;
|
|
480
|
-
// Exact matches (no wildcards/params) come before wildcard/param routes
|
|
481
|
-
const aHasWildcard = a.path.includes('*') || a.path.includes(':');
|
|
482
|
-
const bHasWildcard = b.path.includes('*') || b.path.includes(':');
|
|
483
|
-
if (!aHasWildcard && bHasWildcard)
|
|
484
|
-
return -1;
|
|
485
|
-
if (aHasWildcard && !bHasWildcard)
|
|
486
|
-
return 1;
|
|
487
|
-
// Among routes with same wildcard status, longer paths are more specific
|
|
488
|
-
if (a.path.length !== b.path.length) {
|
|
489
|
-
return b.path.length - a.path.length;
|
|
490
|
-
}
|
|
491
|
-
return 0;
|
|
492
|
-
};
|
|
493
|
-
/**
|
|
494
|
-
* Sorts view items by route specificity (most specific first).
|
|
495
|
-
*
|
|
496
|
-
* Sort order aligns with findViewItemByPath in ReactRouterViewStack.tsx:
|
|
497
|
-
* 1. Index routes come first
|
|
498
|
-
* 2. Wildcard-only routes (* or /*) come last
|
|
499
|
-
* 3. Exact matches (no wildcards/params) come before wildcard/param routes
|
|
500
|
-
* 4. Among routes with same wildcard status, longer paths are more specific
|
|
501
|
-
*
|
|
502
|
-
* @param views The view items to sort.
|
|
503
|
-
* @returns A new sorted array of view items.
|
|
504
|
-
*/
|
|
505
|
-
const sortViewsBySpecificity = (views) => {
|
|
506
|
-
return [...views].sort((a, b) => {
|
|
507
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
508
|
-
return compareRouteSpecificity({ path: ((_b = (_a = a.routeData) === null || _a === void 0 ? void 0 : _a.childProps) === null || _b === void 0 ? void 0 : _b.path) || '', index: !!((_d = (_c = a.routeData) === null || _c === void 0 ? void 0 : _c.childProps) === null || _d === void 0 ? void 0 : _d.index) }, { path: ((_f = (_e = b.routeData) === null || _e === void 0 ? void 0 : _e.childProps) === null || _f === void 0 ? void 0 : _f.path) || '', index: !!((_h = (_g = b.routeData) === null || _g === void 0 ? void 0 : _g.childProps) === null || _h === void 0 ? void 0 : _h.index) });
|
|
509
|
-
});
|
|
38
|
+
return match;
|
|
510
39
|
};
|
|
511
40
|
|
|
512
|
-
/**
|
|
513
|
-
* `ReactRouterViewStack` is a custom navigation manager used in Ionic React
|
|
514
|
-
* apps to map React Router route elements (such as `<IonRoute>`) to "view
|
|
515
|
-
* items" that Ionic can manage in a view stack. This is critical to maintain
|
|
516
|
-
* Ionic’s animation, lifecycle, and history behavior across views.
|
|
517
|
-
*/
|
|
518
|
-
/**
|
|
519
|
-
* Delay in milliseconds before removing a Navigate view item after a redirect.
|
|
520
|
-
* This ensures the redirect navigation completes before the view is removed.
|
|
521
|
-
*/
|
|
522
|
-
const NAVIGATE_REDIRECT_DELAY_MS = 100;
|
|
523
|
-
/**
|
|
524
|
-
* Delay in milliseconds before cleaning up a view without an IonPage element.
|
|
525
|
-
* This double-checks that the view is truly not needed before removal.
|
|
526
|
-
*/
|
|
527
|
-
const VIEW_CLEANUP_DELAY_MS = 200;
|
|
528
|
-
/**
|
|
529
|
-
* Computes the absolute pathnameBase for a route element based on its type.
|
|
530
|
-
* Handles relative paths, index routes, and splat routes differently.
|
|
531
|
-
*/
|
|
532
|
-
const computeAbsolutePathnameBase = (routeElement, routeMatch, parentPathnameBase, routeInfoPathname) => {
|
|
533
|
-
const routePath = routeElement.props.path;
|
|
534
|
-
const isRelativePath = routePath && !routePath.startsWith('/');
|
|
535
|
-
const isIndexRoute = !!routeElement.props.index;
|
|
536
|
-
const isSplatOnlyRoute = routePath === '*' || routePath === '/*';
|
|
537
|
-
if (isSplatOnlyRoute) {
|
|
538
|
-
// Splat routes should NOT contribute their matched portion to pathnameBase
|
|
539
|
-
// This aligns with React Router v7's v7_relativeSplatPath behavior
|
|
540
|
-
return parentPathnameBase;
|
|
541
|
-
}
|
|
542
|
-
if (isRelativePath && (routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch.pathnameBase)) {
|
|
543
|
-
const relativeBase = routeMatch.pathnameBase.startsWith('/')
|
|
544
|
-
? routeMatch.pathnameBase.slice(1)
|
|
545
|
-
: routeMatch.pathnameBase;
|
|
546
|
-
return parentPathnameBase === '/' ? `/${relativeBase}` : `${parentPathnameBase}/${relativeBase}`;
|
|
547
|
-
}
|
|
548
|
-
if (isIndexRoute) {
|
|
549
|
-
return parentPathnameBase;
|
|
550
|
-
}
|
|
551
|
-
return (routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch.pathnameBase) || routeInfoPathname;
|
|
552
|
-
};
|
|
553
|
-
/**
|
|
554
|
-
* Gets fallback params from view items in other outlets when parent context is empty.
|
|
555
|
-
* This handles cases where React context propagation doesn't work as expected.
|
|
556
|
-
*/
|
|
557
|
-
const getFallbackParamsFromViewItems = (allViewItems, currentOutletId, currentPathname) => {
|
|
558
|
-
var _a;
|
|
559
|
-
const matchingViews = [];
|
|
560
|
-
for (const otherViewItem of allViewItems) {
|
|
561
|
-
if (otherViewItem.outletId === currentOutletId)
|
|
562
|
-
continue;
|
|
563
|
-
const otherMatch = (_a = otherViewItem.routeData) === null || _a === void 0 ? void 0 : _a.match;
|
|
564
|
-
if ((otherMatch === null || otherMatch === void 0 ? void 0 : otherMatch.params) && Object.keys(otherMatch.params).length > 0) {
|
|
565
|
-
const matchedPathname = otherMatch.pathnameBase || otherMatch.pathname;
|
|
566
|
-
if (matchedPathname && currentPathname.startsWith(matchedPathname)) {
|
|
567
|
-
matchingViews.push({
|
|
568
|
-
params: otherMatch.params,
|
|
569
|
-
pathLength: matchedPathname.length,
|
|
570
|
-
});
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
// Sort ascending by path length so more-specific (longer) paths are applied
|
|
575
|
-
// last and their params take priority over less-specific ones.
|
|
576
|
-
matchingViews.sort((a, b) => a.pathLength - b.pathLength);
|
|
577
|
-
const params = {};
|
|
578
|
-
for (const view of matchingViews) {
|
|
579
|
-
Object.assign(params, view.params);
|
|
580
|
-
}
|
|
581
|
-
return params;
|
|
582
|
-
};
|
|
583
|
-
/**
|
|
584
|
-
* Builds the matches array for RouteContext.
|
|
585
|
-
*/
|
|
586
|
-
const buildContextMatches = (parentMatches, combinedParams, routeMatch, routeInfoPathname, absolutePathnameBase, viewItem, routeElement, componentElement) => {
|
|
587
|
-
return [
|
|
588
|
-
...parentMatches,
|
|
589
|
-
{
|
|
590
|
-
params: combinedParams,
|
|
591
|
-
pathname: (routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch.pathname) || routeInfoPathname,
|
|
592
|
-
pathnameBase: absolutePathnameBase,
|
|
593
|
-
route: {
|
|
594
|
-
id: viewItem.id,
|
|
595
|
-
path: routeElement.props.path,
|
|
596
|
-
element: componentElement,
|
|
597
|
-
index: !!routeElement.props.index,
|
|
598
|
-
caseSensitive: routeElement.props.caseSensitive,
|
|
599
|
-
hasErrorBoundary: false,
|
|
600
|
-
},
|
|
601
|
-
},
|
|
602
|
-
];
|
|
603
|
-
};
|
|
604
|
-
const createDefaultMatch = (fullPathname, routeProps) => {
|
|
605
|
-
var _a, _b;
|
|
606
|
-
const isIndexRoute = !!routeProps.index;
|
|
607
|
-
const patternPath = (_a = routeProps.path) !== null && _a !== void 0 ? _a : '';
|
|
608
|
-
const pathnameBase = fullPathname === '' ? '/' : fullPathname;
|
|
609
|
-
const computedEnd = routeProps.end !== undefined ? routeProps.end : patternPath !== '' ? !patternPath.endsWith('*') : true;
|
|
610
|
-
return {
|
|
611
|
-
params: {},
|
|
612
|
-
pathname: isIndexRoute ? '' : fullPathname,
|
|
613
|
-
pathnameBase,
|
|
614
|
-
pattern: {
|
|
615
|
-
path: patternPath,
|
|
616
|
-
caseSensitive: (_b = routeProps.caseSensitive) !== null && _b !== void 0 ? _b : false,
|
|
617
|
-
end: isIndexRoute ? true : computedEnd,
|
|
618
|
-
},
|
|
619
|
-
};
|
|
620
|
-
};
|
|
621
|
-
const computeRelativeToParent = (pathname, parentPath) => {
|
|
622
|
-
if (!parentPath)
|
|
623
|
-
return null;
|
|
624
|
-
const normalizedParent = normalizePathnameForComparison(parentPath);
|
|
625
|
-
const normalizedPathname = normalizePathnameForComparison(pathname);
|
|
626
|
-
if (normalizedPathname === normalizedParent) {
|
|
627
|
-
return '';
|
|
628
|
-
}
|
|
629
|
-
const withSlash = normalizedParent === '/' ? '/' : normalizedParent + '/';
|
|
630
|
-
if (normalizedPathname.startsWith(withSlash)) {
|
|
631
|
-
return normalizedPathname.slice(withSlash.length);
|
|
632
|
-
}
|
|
633
|
-
return null;
|
|
634
|
-
};
|
|
635
|
-
const resolveIndexRouteMatch = (viewItem, pathname, parentPath) => {
|
|
636
|
-
var _a, _b, _c;
|
|
637
|
-
if (!((_b = (_a = viewItem.routeData) === null || _a === void 0 ? void 0 : _a.childProps) === null || _b === void 0 ? void 0 : _b.index)) {
|
|
638
|
-
return null;
|
|
639
|
-
}
|
|
640
|
-
// Prefer computing against the parent path when available to align with RRv6 semantics
|
|
641
|
-
const relative = computeRelativeToParent(pathname, parentPath);
|
|
642
|
-
if (relative !== null) {
|
|
643
|
-
// Index routes match only when there is no remaining path
|
|
644
|
-
if (relative === '' || relative === '/') {
|
|
645
|
-
return createDefaultMatch(parentPath || pathname, viewItem.routeData.childProps);
|
|
646
|
-
}
|
|
647
|
-
return null;
|
|
648
|
-
}
|
|
649
|
-
// Fallback: use previously computed match base for equality check
|
|
650
|
-
const previousMatch = (_c = viewItem.routeData) === null || _c === void 0 ? void 0 : _c.match;
|
|
651
|
-
if (!previousMatch) {
|
|
652
|
-
return null;
|
|
653
|
-
}
|
|
654
|
-
const normalizedPathname = normalizePathnameForComparison(pathname);
|
|
655
|
-
const normalizedBase = normalizePathnameForComparison(previousMatch.pathnameBase || previousMatch.pathname || '');
|
|
656
|
-
return normalizedPathname === normalizedBase ? previousMatch : null;
|
|
657
|
-
};
|
|
658
41
|
class ReactRouterViewStack extends ViewStacks {
|
|
659
42
|
constructor() {
|
|
660
43
|
super();
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
* Associates route props with the matched route path for further lookups.
|
|
676
|
-
*/
|
|
677
|
-
this.createViewItem = (outletId, reactElement, routeInfo, page) => {
|
|
678
|
-
var _a, _b;
|
|
679
|
-
const routePath = reactElement.props.path || '';
|
|
680
|
-
// Check if we already have a view item for this exact route that we can reuse
|
|
681
|
-
// Include wildcard routes like tabs/* since they should be reused
|
|
682
|
-
// Also check unmounted items that might have been preserved for browser navigation
|
|
683
|
-
const existingViewItem = this.getViewItemsForOutlet(outletId).find((v) => {
|
|
684
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
685
|
-
const existingRouteProps = (_b = (_a = v.reactElement) === null || _a === void 0 ? void 0 : _a.props) !== null && _b !== void 0 ? _b : {};
|
|
686
|
-
const existingPath = existingRouteProps.path || '';
|
|
687
|
-
const existingElement = existingRouteProps.element;
|
|
688
|
-
const newElement = reactElement.props.element;
|
|
689
|
-
const existingIsIndexRoute = !!existingRouteProps.index;
|
|
690
|
-
const newIsIndexRoute = !!reactElement.props.index;
|
|
691
|
-
// For Navigate components, match by destination
|
|
692
|
-
const existingIsNavigate = React.isValidElement(existingElement) && existingElement.type === Navigate;
|
|
693
|
-
const newIsNavigate = React.isValidElement(newElement) && newElement.type === Navigate;
|
|
694
|
-
if (existingIsNavigate && newIsNavigate) {
|
|
695
|
-
const existingTo = (_c = existingElement.props) === null || _c === void 0 ? void 0 : _c.to;
|
|
696
|
-
const newTo = (_d = newElement.props) === null || _d === void 0 ? void 0 : _d.to;
|
|
697
|
-
if (existingTo === newTo) {
|
|
698
|
-
return true;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
if (existingIsIndexRoute && newIsIndexRoute) {
|
|
702
|
-
return true;
|
|
703
|
-
}
|
|
704
|
-
// Reuse view items with the same path
|
|
705
|
-
// Special case: reuse tabs/* and other specific wildcard routes
|
|
706
|
-
// Don't reuse index routes (empty path) or generic catch-all wildcards (*)
|
|
707
|
-
if (existingPath === routePath && existingPath !== '' && existingPath !== '*') {
|
|
708
|
-
// Parameterized routes need pathname matching to ensure /details/1 and /details/2
|
|
709
|
-
// get separate view items. For wildcard routes (e.g., user/:userId/*), compare
|
|
710
|
-
// pathnameBase to allow child path changes while preserving the parent view.
|
|
711
|
-
const hasParams = routePath.includes(':');
|
|
712
|
-
const isWildcard = routePath.includes('*');
|
|
713
|
-
if (hasParams) {
|
|
714
|
-
if (isWildcard) {
|
|
715
|
-
const existingPathnameBase = (_f = (_e = v.routeData) === null || _e === void 0 ? void 0 : _e.match) === null || _f === void 0 ? void 0 : _f.pathnameBase;
|
|
716
|
-
const newMatch = matchComponent$1(reactElement, routeInfo.pathname, false, this.outletParentPaths.get(outletId));
|
|
717
|
-
const newPathnameBase = newMatch === null || newMatch === void 0 ? void 0 : newMatch.pathnameBase;
|
|
718
|
-
if (existingPathnameBase !== newPathnameBase) {
|
|
719
|
-
return false;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
const existingPathname = (_h = (_g = v.routeData) === null || _g === void 0 ? void 0 : _g.match) === null || _h === void 0 ? void 0 : _h.pathname;
|
|
724
|
-
if (existingPathname !== routeInfo.pathname) {
|
|
725
|
-
return false;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
// Also reuse specific wildcard routes like tabs/*
|
|
732
|
-
if (existingPath === routePath && existingPath.endsWith('/*') && existingPath !== '/*') {
|
|
733
|
-
return true;
|
|
734
|
-
}
|
|
735
|
-
return false;
|
|
736
|
-
});
|
|
737
|
-
if (existingViewItem) {
|
|
738
|
-
// Update and ensure the existing view item is properly configured
|
|
739
|
-
existingViewItem.reactElement = reactElement;
|
|
740
|
-
existingViewItem.mount = true;
|
|
741
|
-
existingViewItem.ionPageElement = page || existingViewItem.ionPageElement;
|
|
742
|
-
const updatedMatch = matchComponent$1(reactElement, routeInfo.pathname, false, this.outletParentPaths.get(outletId)) ||
|
|
743
|
-
((_a = existingViewItem.routeData) === null || _a === void 0 ? void 0 : _a.match) ||
|
|
744
|
-
createDefaultMatch(routeInfo.pathname, reactElement.props);
|
|
745
|
-
existingViewItem.routeData = {
|
|
746
|
-
match: updatedMatch,
|
|
747
|
-
childProps: reactElement.props,
|
|
748
|
-
lastPathname: (_b = existingViewItem.routeData) === null || _b === void 0 ? void 0 : _b.lastPathname, // Preserve navigation history
|
|
749
|
-
};
|
|
750
|
-
return existingViewItem;
|
|
751
|
-
}
|
|
752
|
-
const id = `${outletId}-${generateId(outletId)}`;
|
|
753
|
-
const viewItem = {
|
|
754
|
-
id,
|
|
755
|
-
outletId,
|
|
756
|
-
ionPageElement: page,
|
|
757
|
-
reactElement,
|
|
758
|
-
mount: true,
|
|
759
|
-
ionRoute: true,
|
|
760
|
-
};
|
|
761
|
-
if (reactElement.type === IonRoute) {
|
|
762
|
-
viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement;
|
|
763
|
-
}
|
|
764
|
-
const initialMatch = matchComponent$1(reactElement, routeInfo.pathname, true, this.outletParentPaths.get(outletId)) ||
|
|
765
|
-
createDefaultMatch(routeInfo.pathname, reactElement.props);
|
|
766
|
-
viewItem.routeData = {
|
|
767
|
-
match: initialMatch,
|
|
768
|
-
childProps: reactElement.props,
|
|
769
|
-
};
|
|
770
|
-
this.add(viewItem);
|
|
771
|
-
return viewItem;
|
|
44
|
+
this.createViewItem = this.createViewItem.bind(this);
|
|
45
|
+
this.findViewItemByRouteInfo = this.findViewItemByRouteInfo.bind(this);
|
|
46
|
+
this.findLeavingViewItemByRouteInfo = this.findLeavingViewItemByRouteInfo.bind(this);
|
|
47
|
+
this.getChildrenToRender = this.getChildrenToRender.bind(this);
|
|
48
|
+
this.findViewItemByPathname = this.findViewItemByPathname.bind(this);
|
|
49
|
+
}
|
|
50
|
+
createViewItem(outletId, reactElement, routeInfo, page) {
|
|
51
|
+
const viewItem = {
|
|
52
|
+
id: generateId('viewItem'),
|
|
53
|
+
outletId,
|
|
54
|
+
ionPageElement: page,
|
|
55
|
+
reactElement,
|
|
56
|
+
mount: true,
|
|
57
|
+
ionRoute: false,
|
|
772
58
|
};
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
const routePath = viewItem.reactElement.props.path || '';
|
|
784
|
-
let match = matchComponent$1(viewItem.reactElement, routeInfo.pathname, false, parentPath);
|
|
785
|
-
if (!match) {
|
|
786
|
-
const indexMatch = resolveIndexRouteMatch(viewItem, routeInfo.pathname, parentPath);
|
|
787
|
-
if (indexMatch) {
|
|
788
|
-
match = indexMatch;
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
// For parameterized routes, check if this is a navigation to a different path instance
|
|
792
|
-
// In that case, we should NOT reuse this view - a new view should be created
|
|
793
|
-
const isParameterRoute = routePath.includes(':');
|
|
794
|
-
const previousMatch = (_a = viewItem.routeData) === null || _a === void 0 ? void 0 : _a.match;
|
|
795
|
-
const isSamePath = (match === null || match === void 0 ? void 0 : match.pathname) === (previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.pathname);
|
|
796
|
-
// Flag to indicate this view should not be reused for this different parameterized path
|
|
797
|
-
const shouldSkipForDifferentParam = isParameterRoute && match && previousMatch && !isSamePath;
|
|
798
|
-
// Don't deactivate views automatically - let the StackManager handle view lifecycle
|
|
799
|
-
// This preserves views in the stack for navigation history like native apps
|
|
800
|
-
// Views will be hidden/shown by the StackManager's transition logic instead of being unmounted
|
|
801
|
-
// Special handling for Navigate components - they should unmount after redirecting
|
|
802
|
-
const elementComponent = (_c = (_b = viewItem.reactElement) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.element;
|
|
803
|
-
const isNavigateComponent = isNavigateElement(elementComponent);
|
|
804
|
-
if (isNavigateComponent) {
|
|
805
|
-
// Navigate components should only be mounted when they match
|
|
806
|
-
// Once they redirect (no longer match), they should be removed completely
|
|
807
|
-
// IMPORTANT: For index routes, we need to check indexMatch too since matchComponent
|
|
808
|
-
// may not properly match index routes without explicit parent path context
|
|
809
|
-
const indexMatch = ((_e = (_d = viewItem.routeData) === null || _d === void 0 ? void 0 : _d.childProps) === null || _e === void 0 ? void 0 : _e.index)
|
|
810
|
-
? resolveIndexRouteMatch(viewItem, routeInfo.pathname, parentPath)
|
|
811
|
-
: null;
|
|
812
|
-
const hasValidMatch = match || indexMatch;
|
|
813
|
-
if (!hasValidMatch && viewItem.mount) {
|
|
814
|
-
viewItem.mount = false;
|
|
815
|
-
// Schedule removal of the Navigate view item after a short delay
|
|
816
|
-
// This ensures the redirect completes before removal
|
|
817
|
-
setTimeout(() => {
|
|
818
|
-
this.remove(viewItem);
|
|
819
|
-
reRender === null || reRender === void 0 ? void 0 : reRender();
|
|
820
|
-
}, NAVIGATE_REDIRECT_DELAY_MS);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
// Components that don't have IonPage elements and no longer match should be cleaned up
|
|
824
|
-
// BUT we need to be careful not to remove them if they're part of browser navigation history
|
|
825
|
-
// This handles components that perform immediate actions like programmatic navigation
|
|
826
|
-
// EXCEPTION: Navigate components should ALWAYS remain mounted until they redirect
|
|
827
|
-
// since they need to be rendered to trigger the navigation
|
|
828
|
-
if (!match && viewItem.mount && !viewItem.ionPageElement && !isNavigateComponent) {
|
|
829
|
-
// Check if this view item should be preserved for browser navigation
|
|
830
|
-
// We'll keep it if it was recently active (within the last navigation)
|
|
831
|
-
const shouldPreserve = viewItem.routeData.lastPathname === routeInfo.pathname ||
|
|
832
|
-
((_f = viewItem.routeData.match) === null || _f === void 0 ? void 0 : _f.pathname) === routeInfo.lastPathname;
|
|
833
|
-
if (!shouldPreserve) {
|
|
834
|
-
// This view item doesn't match and doesn't have an IonPage
|
|
835
|
-
// It's likely a utility component that performs an action and navigates away
|
|
836
|
-
viewItem.mount = false;
|
|
837
|
-
// Schedule removal to allow it to be recreated on next navigation
|
|
838
|
-
setTimeout(() => {
|
|
839
|
-
// Double-check before removing - the view might be needed again
|
|
840
|
-
const stillNotNeeded = !viewItem.mount && !viewItem.ionPageElement;
|
|
841
|
-
if (stillNotNeeded) {
|
|
842
|
-
this.remove(viewItem);
|
|
843
|
-
reRender === null || reRender === void 0 ? void 0 : reRender();
|
|
844
|
-
}
|
|
845
|
-
}, VIEW_CLEANUP_DELAY_MS);
|
|
846
|
-
}
|
|
847
|
-
else {
|
|
848
|
-
// Preserve it but unmount it for now
|
|
849
|
-
viewItem.mount = false;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
// Reactivate view if it matches but was previously deactivated
|
|
853
|
-
// Don't reactivate if this is a parameterized route navigating to a different path instance
|
|
854
|
-
// Don't reactivate catch-all wildcard routes — they are created fresh by createViewItem
|
|
855
|
-
const isCatchAllWildcard = routePath === '*' || routePath === '/*';
|
|
856
|
-
if (match && !viewItem.mount && !shouldSkipForDifferentParam && !isCatchAllWildcard) {
|
|
857
|
-
viewItem.mount = true;
|
|
858
|
-
viewItem.routeData.match = match;
|
|
859
|
-
}
|
|
860
|
-
// Deactivate wildcard (catch-all) and empty-path (default) routes when a more-specific route matches.
|
|
861
|
-
// This prevents "Not found" or fallback pages from showing alongside valid routes.
|
|
862
|
-
if (routePath === '*' || routePath === '') {
|
|
863
|
-
// Check if any other view in this outlet has a match for the current route
|
|
864
|
-
const outletViews = this.getViewItemsForOutlet(viewItem.outletId);
|
|
865
|
-
// When parent path context is available, compute the relative pathname once
|
|
866
|
-
// outside the loop since both routeInfo.pathname and parentPath are invariant.
|
|
867
|
-
const relativePathname = parentPath
|
|
868
|
-
? computeRelativeToParent(routeInfo.pathname, parentPath)
|
|
869
|
-
: null;
|
|
870
|
-
let hasSpecificMatch = outletViews.some((v) => {
|
|
871
|
-
var _a, _b;
|
|
872
|
-
if (v.id === viewItem.id)
|
|
873
|
-
return false; // Skip self
|
|
874
|
-
const vRoutePath = ((_b = (_a = v.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path) || '';
|
|
875
|
-
if (vRoutePath === '*' || vRoutePath === '')
|
|
876
|
-
return false; // Skip other wildcard/empty routes
|
|
877
|
-
// When parent path context is available and the route is relative, use
|
|
878
|
-
// parent-path-aware matching. This avoids false positives from
|
|
879
|
-
// derivePathnameToMatch's tail-slice heuristic, which can incorrectly
|
|
880
|
-
// match route literals that appear at the wrong position in the pathname.
|
|
881
|
-
// Example: pathname /parent/extra/details/99 with route details/:id —
|
|
882
|
-
// the tail-slice extracts ["details","99"] producing a false match.
|
|
883
|
-
if (parentPath && vRoutePath && !vRoutePath.startsWith('/')) {
|
|
884
|
-
if (relativePathname === null) {
|
|
885
|
-
return false; // Pathname is outside this outlet's parent scope
|
|
886
|
-
}
|
|
887
|
-
return !!matchPath({
|
|
888
|
-
pathname: relativePathname,
|
|
889
|
-
componentProps: v.reactElement.props,
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
// Fallback to matchComponent when no parent path context is available
|
|
893
|
-
const vMatch = v.reactElement ? matchComponent$1(v.reactElement, routeInfo.pathname) : null;
|
|
894
|
-
return !!vMatch;
|
|
895
|
-
});
|
|
896
|
-
// For catch-all * routes, also deactivate when the pathname matches the outlet's
|
|
897
|
-
// parent path exactly. This means there are no remaining segments for the wildcard
|
|
898
|
-
// to catch, so the empty-path or index route should handle it instead.
|
|
899
|
-
if (!hasSpecificMatch && routePath === '*') {
|
|
900
|
-
const outletParentPath = this.outletParentPaths.get(viewItem.outletId);
|
|
901
|
-
if (outletParentPath) {
|
|
902
|
-
const normalizedParent = normalizePathnameForComparison(outletParentPath);
|
|
903
|
-
const normalizedPathname = normalizePathnameForComparison(routeInfo.pathname);
|
|
904
|
-
if (normalizedPathname === normalizedParent) {
|
|
905
|
-
// Check if there's an empty-path or index view item that should handle this
|
|
906
|
-
const hasDefaultRoute = outletViews.some((v) => {
|
|
907
|
-
var _a, _b, _c, _d;
|
|
908
|
-
if (v.id === viewItem.id)
|
|
909
|
-
return false;
|
|
910
|
-
const vRoutePath = (_b = (_a = v.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
911
|
-
return vRoutePath === '' || vRoutePath === undefined || !!((_d = (_c = v.routeData) === null || _c === void 0 ? void 0 : _c.childProps) === null || _d === void 0 ? void 0 : _d.index);
|
|
912
|
-
});
|
|
913
|
-
if (hasDefaultRoute) {
|
|
914
|
-
hasSpecificMatch = true;
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
if (hasSpecificMatch) {
|
|
920
|
-
viewItem.mount = false;
|
|
921
|
-
if (viewItem.ionPageElement) {
|
|
922
|
-
viewItem.ionPageElement.classList.add('ion-page-hidden');
|
|
923
|
-
viewItem.ionPageElement.setAttribute('aria-hidden', 'true');
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
const routeElement = React.cloneElement(viewItem.reactElement);
|
|
928
|
-
const componentElement = routeElement.props.element;
|
|
929
|
-
// Don't update match for parameterized routes navigating to different path instances
|
|
930
|
-
// This preserves the original match so that findViewItemByPath can correctly skip this view
|
|
931
|
-
if (match && viewItem.routeData.match !== match && !shouldSkipForDifferentParam) {
|
|
932
|
-
viewItem.routeData.match = match;
|
|
933
|
-
}
|
|
934
|
-
const routeMatch = shouldSkipForDifferentParam ? (_g = viewItem.routeData) === null || _g === void 0 ? void 0 : _g.match : match || ((_h = viewItem.routeData) === null || _h === void 0 ? void 0 : _h.match);
|
|
935
|
-
return (React.createElement(UNSAFE_RouteContext.Consumer, { key: `view-context-${viewItem.id}` }, (parentContext) => {
|
|
936
|
-
var _a, _b;
|
|
937
|
-
const parentMatches = ((_a = parentContext === null || parentContext === void 0 ? void 0 : parentContext.matches) !== null && _a !== void 0 ? _a : []);
|
|
938
|
-
// Accumulate params from parent matches, with fallback to other outlets
|
|
939
|
-
let accumulatedParentParams = parentMatches.reduce((acc, m) => (Object.assign(Object.assign({}, acc), m.params)), {});
|
|
940
|
-
if (parentMatches.length === 0 && Object.keys(accumulatedParentParams).length === 0) {
|
|
941
|
-
accumulatedParentParams = getFallbackParamsFromViewItems(this.getAllViewItems(), viewItem.outletId, routeInfo.pathname);
|
|
942
|
-
}
|
|
943
|
-
const combinedParams = Object.assign(Object.assign({}, accumulatedParentParams), ((_b = routeMatch === null || routeMatch === void 0 ? void 0 : routeMatch.params) !== null && _b !== void 0 ? _b : {}));
|
|
944
|
-
const parentPathnameBase = parentMatches.length > 0 ? parentMatches[parentMatches.length - 1].pathnameBase : '/';
|
|
945
|
-
const absolutePathnameBase = computeAbsolutePathnameBase(routeElement, routeMatch, parentPathnameBase, routeInfo.pathname);
|
|
946
|
-
const contextMatches = buildContextMatches(parentMatches, combinedParams, routeMatch, routeInfo.pathname, absolutePathnameBase, viewItem, routeElement, componentElement);
|
|
947
|
-
const routeContextValue = parentContext
|
|
948
|
-
? Object.assign(Object.assign({}, parentContext), { matches: contextMatches }) : { outlet: null, matches: contextMatches, isDataRoute: false };
|
|
949
|
-
return (React.createElement(ViewLifeCycleManager, { key: `view-${viewItem.id}`, mount: viewItem.mount, removeView: () => this.remove(viewItem) },
|
|
950
|
-
React.createElement(UNSAFE_RouteContext.Provider, { value: routeContextValue }, componentElement)));
|
|
951
|
-
}));
|
|
59
|
+
if (reactElement.type === IonRoute) {
|
|
60
|
+
viewItem.ionRoute = true;
|
|
61
|
+
viewItem.disableIonPageManagement = reactElement.props.disableIonPageManagement;
|
|
62
|
+
}
|
|
63
|
+
viewItem.routeData = {
|
|
64
|
+
match: matchPath({
|
|
65
|
+
pathname: routeInfo.pathname,
|
|
66
|
+
componentProps: reactElement.props,
|
|
67
|
+
}),
|
|
68
|
+
childProps: reactElement.props,
|
|
952
69
|
};
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
* Each view is wrapped in <ViewLifeCycleManager> to manage lifecycle and rendering
|
|
962
|
-
*/
|
|
963
|
-
this.getChildrenToRender = (outletId, ionRouterOutlet, routeInfo, reRender, parentPathnameBase) => {
|
|
964
|
-
const viewItems = this.getViewItemsForOutlet(outletId);
|
|
965
|
-
// Seed the mount path from the parent route context if available.
|
|
966
|
-
// This provides the outlet's mount path immediately on first render,
|
|
967
|
-
// eliminating the need for heuristic-based discovery in computeParentPath.
|
|
968
|
-
if (parentPathnameBase && !this.outletMountPaths.has(outletId)) {
|
|
969
|
-
this.outletMountPaths.set(outletId, parentPathnameBase);
|
|
970
|
-
}
|
|
971
|
-
// Determine parentPath for outlets with relative or index routes.
|
|
972
|
-
// This populates outletParentPaths for findViewItemByPath's matchView
|
|
973
|
-
// and the catch-all deactivation logic in renderViewItem.
|
|
974
|
-
let parentPath = undefined;
|
|
975
|
-
try {
|
|
976
|
-
const routeChildren = extractRouteChildren(ionRouterOutlet.props.children);
|
|
977
|
-
const { hasRelativeRoutes, hasIndexRoute, hasWildcardRoute } = analyzeRouteChildren(routeChildren);
|
|
978
|
-
if (hasRelativeRoutes || hasIndexRoute) {
|
|
979
|
-
const result = computeParentPath({
|
|
980
|
-
currentPathname: routeInfo.pathname,
|
|
981
|
-
outletMountPath: this.outletMountPaths.get(outletId),
|
|
982
|
-
routeChildren,
|
|
983
|
-
hasRelativeRoutes,
|
|
984
|
-
hasIndexRoute,
|
|
985
|
-
hasWildcardRoute,
|
|
986
|
-
});
|
|
987
|
-
parentPath = result.parentPath;
|
|
988
|
-
// Persist the mount path for subsequent calls, mirroring StackManager.outletMountPath.
|
|
989
|
-
// Unlike outletParentPaths (cleared when parentPath is undefined), the mount path is
|
|
990
|
-
// intentionally sticky — it anchors the outlet's scope and is only removed in clear().
|
|
991
|
-
if (result.outletMountPath && !this.outletMountPaths.has(outletId)) {
|
|
992
|
-
this.outletMountPaths.set(outletId, result.outletMountPath);
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
catch (e) {
|
|
997
|
-
// Non-fatal: if we fail to compute parentPath, fall back to previous behavior
|
|
998
|
-
}
|
|
999
|
-
// Store the computed parentPath for use in findViewItemByPath.
|
|
1000
|
-
// Clear stale entries when parentPath is undefined (e.g., navigated out of scope).
|
|
1001
|
-
if (parentPath !== undefined) {
|
|
1002
|
-
this.outletParentPaths.set(outletId, parentPath);
|
|
1003
|
-
}
|
|
1004
|
-
else if (this.outletParentPaths.has(outletId)) {
|
|
1005
|
-
this.outletParentPaths.delete(outletId);
|
|
1006
|
-
}
|
|
1007
|
-
// Sync child elements with stored viewItems (e.g. to reflect new props)
|
|
1008
|
-
React.Children.forEach(ionRouterOutlet.props.children, (child) => {
|
|
1009
|
-
// Ensure the child is a valid React element since we
|
|
1010
|
-
// might have whitespace strings or other non-element children
|
|
1011
|
-
if (React.isValidElement(child)) {
|
|
1012
|
-
// Find view item by exact path match to avoid wildcard routes overwriting specific routes
|
|
1013
|
-
const childPath = child.props.path;
|
|
1014
|
-
const viewItem = viewItems.find((v) => {
|
|
1015
|
-
var _a, _b;
|
|
1016
|
-
const viewItemPath = (_b = (_a = v.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
1017
|
-
// Only update if paths match exactly (prevents wildcard routes from overwriting specific routes)
|
|
1018
|
-
return viewItemPath === childPath;
|
|
1019
|
-
});
|
|
1020
|
-
if (viewItem) {
|
|
1021
|
-
viewItem.reactElement = child;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
});
|
|
1025
|
-
// Filter out duplicate view items by ID (but keep all mounted items)
|
|
1026
|
-
const uniqueViewItems = viewItems.filter((viewItem, index, array) => {
|
|
1027
|
-
// Remove duplicates by ID (keep first occurrence)
|
|
1028
|
-
const isFirstOccurrence = array.findIndex((v) => v.id === viewItem.id) === index;
|
|
1029
|
-
return isFirstOccurrence;
|
|
70
|
+
return viewItem;
|
|
71
|
+
}
|
|
72
|
+
getChildrenToRender(outletId, ionRouterOutlet, routeInfo) {
|
|
73
|
+
const viewItems = this.getViewItemsForOutlet(outletId);
|
|
74
|
+
// Sync latest routes with viewItems
|
|
75
|
+
React.Children.forEach(ionRouterOutlet.props.children, (child) => {
|
|
76
|
+
const viewItem = viewItems.find((v) => {
|
|
77
|
+
return matchComponent$1(child, v.routeData.childProps.path || v.routeData.childProps.from);
|
|
1030
78
|
});
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
const renderableViewItems = uniqueViewItems.filter((viewItem) => {
|
|
1034
|
-
var _a, _b, _c, _d;
|
|
1035
|
-
const elementComponent = (_b = (_a = viewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.element;
|
|
1036
|
-
const isNavigateComponent = isNavigateElement(elementComponent);
|
|
1037
|
-
// Exclude unmounted Navigate components from rendering
|
|
1038
|
-
if (isNavigateComponent && !viewItem.mount) {
|
|
1039
|
-
return false;
|
|
1040
|
-
}
|
|
1041
|
-
// Filter out views that are unmounted, have no ionPageElement, and don't match the current route.
|
|
1042
|
-
// These are "stale" views from previous routes that should not be rendered.
|
|
1043
|
-
// Views WITH ionPageElement are handled by the normal lifecycle events.
|
|
1044
|
-
// Views that MATCH the current route should be kept (they might be transitioning).
|
|
1045
|
-
if (!viewItem.mount && !viewItem.ionPageElement) {
|
|
1046
|
-
// Check if this view's route path matches the current pathname
|
|
1047
|
-
const viewRoutePath = (_d = (_c = viewItem.reactElement) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.path;
|
|
1048
|
-
if (viewRoutePath) {
|
|
1049
|
-
// First try exact match using matchComponent
|
|
1050
|
-
const routeMatch = matchComponent$1(viewItem.reactElement, routeInfo.pathname, false, parentPath);
|
|
1051
|
-
if (routeMatch) {
|
|
1052
|
-
// View matches current route, keep it
|
|
1053
|
-
return true;
|
|
1054
|
-
}
|
|
1055
|
-
// For parent routes (like /multiple-tabs or /routing), check if current pathname
|
|
1056
|
-
// starts with this route's path. This handles views with IonSplitPane/IonTabs
|
|
1057
|
-
// that don't have IonPage but should remain mounted while navigating within their children.
|
|
1058
|
-
const normalizedViewPath = normalizePathnameForComparison(viewRoutePath.replace(/\/?\*$/, '')); // Remove trailing wildcard
|
|
1059
|
-
const normalizedCurrentPath = normalizePathnameForComparison(routeInfo.pathname);
|
|
1060
|
-
// Check if current pathname is within this view's route hierarchy
|
|
1061
|
-
const isWithinRouteHierarchy = normalizedCurrentPath === normalizedViewPath || normalizedCurrentPath.startsWith(normalizedViewPath + '/');
|
|
1062
|
-
if (!isWithinRouteHierarchy) {
|
|
1063
|
-
// View is outside current route hierarchy, remove it
|
|
1064
|
-
setTimeout(() => {
|
|
1065
|
-
this.remove(viewItem);
|
|
1066
|
-
reRender();
|
|
1067
|
-
}, 0);
|
|
1068
|
-
return false;
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
return true;
|
|
1073
|
-
});
|
|
1074
|
-
const renderedItems = renderableViewItems.map((viewItem) => this.renderViewItem(viewItem, routeInfo, parentPath, reRender));
|
|
1075
|
-
return renderedItems;
|
|
1076
|
-
};
|
|
1077
|
-
/**
|
|
1078
|
-
* Finds a view item matching the current route, optionally updating its match state.
|
|
1079
|
-
*/
|
|
1080
|
-
this.findViewItemByRouteInfo = (routeInfo, outletId, updateMatch) => {
|
|
1081
|
-
const { viewItem, match } = this.findViewItemByPath(routeInfo.pathname, outletId);
|
|
1082
|
-
const shouldUpdateMatch = updateMatch === undefined || updateMatch === true;
|
|
1083
|
-
if (shouldUpdateMatch && viewItem && match) {
|
|
1084
|
-
viewItem.routeData.match = match;
|
|
1085
|
-
}
|
|
1086
|
-
return viewItem;
|
|
1087
|
-
};
|
|
1088
|
-
/**
|
|
1089
|
-
* Finds the view item that was previously active before a route change.
|
|
1090
|
-
*/
|
|
1091
|
-
this.findLeavingViewItemByRouteInfo = (routeInfo, outletId, mustBeIonRoute = true) => {
|
|
1092
|
-
// If the lastPathname is not set, we cannot find a leaving view item
|
|
1093
|
-
if (!routeInfo.lastPathname) {
|
|
1094
|
-
return undefined;
|
|
79
|
+
if (viewItem) {
|
|
80
|
+
viewItem.reactElement = child;
|
|
1095
81
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
const { viewItem } = this.findViewItemByPath(pathname, outletId);
|
|
1104
|
-
return viewItem;
|
|
1105
|
-
};
|
|
1106
|
-
/**
|
|
1107
|
-
* Clean up old, unmounted view items to prevent memory leaks
|
|
1108
|
-
*/
|
|
1109
|
-
this.cleanupStaleViewItems = (outletId) => {
|
|
1110
|
-
const viewItems = this.getViewItemsForOutlet(outletId);
|
|
1111
|
-
// Keep only the most recent mounted views and a few unmounted ones for history
|
|
1112
|
-
const maxUnmountedItems = 3;
|
|
1113
|
-
const unmountedItems = viewItems.filter((v) => !v.mount);
|
|
1114
|
-
if (unmountedItems.length > maxUnmountedItems) {
|
|
1115
|
-
// Remove oldest unmounted items
|
|
1116
|
-
const itemsToRemove = unmountedItems.slice(0, unmountedItems.length - maxUnmountedItems);
|
|
1117
|
-
itemsToRemove.forEach((item) => {
|
|
1118
|
-
this.remove(item);
|
|
1119
|
-
});
|
|
82
|
+
});
|
|
83
|
+
const children = viewItems.map((viewItem) => {
|
|
84
|
+
let clonedChild;
|
|
85
|
+
if (viewItem.ionRoute && !viewItem.disableIonPageManagement) {
|
|
86
|
+
clonedChild = (React.createElement(ViewLifeCycleManager, { key: `view-${viewItem.id}`, mount: viewItem.mount, removeView: () => this.remove(viewItem) }, React.cloneElement(viewItem.reactElement, {
|
|
87
|
+
computedMatch: viewItem.routeData.match,
|
|
88
|
+
})));
|
|
1120
89
|
}
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
90
|
+
else {
|
|
91
|
+
const match = matchComponent$1(viewItem.reactElement, routeInfo.pathname);
|
|
92
|
+
clonedChild = (React.createElement(ViewLifeCycleManager, { key: `view-${viewItem.id}`, mount: viewItem.mount, removeView: () => this.remove(viewItem) }, React.cloneElement(viewItem.reactElement, {
|
|
93
|
+
computedMatch: viewItem.routeData.match,
|
|
94
|
+
})));
|
|
95
|
+
if (!match && viewItem.routeData.match) {
|
|
96
|
+
viewItem.routeData.match = undefined;
|
|
97
|
+
viewItem.mount = false;
|
|
98
|
+
}
|
|
1130
99
|
}
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
100
|
+
return clonedChild;
|
|
101
|
+
});
|
|
102
|
+
return children;
|
|
103
|
+
}
|
|
104
|
+
findViewItemByRouteInfo(routeInfo, outletId, updateMatch) {
|
|
105
|
+
const { viewItem, match } = this.findViewItemByPath(routeInfo.pathname, outletId);
|
|
106
|
+
const shouldUpdateMatch = updateMatch === undefined || updateMatch === true;
|
|
107
|
+
if (shouldUpdateMatch && viewItem && match) {
|
|
108
|
+
viewItem.routeData.match = match;
|
|
109
|
+
}
|
|
110
|
+
return viewItem;
|
|
111
|
+
}
|
|
112
|
+
findLeavingViewItemByRouteInfo(routeInfo, outletId, mustBeIonRoute = true) {
|
|
113
|
+
const { viewItem } = this.findViewItemByPath(routeInfo.lastPathname, outletId, mustBeIonRoute);
|
|
114
|
+
return viewItem;
|
|
115
|
+
}
|
|
116
|
+
findViewItemByPathname(pathname, outletId) {
|
|
117
|
+
const { viewItem } = this.findViewItemByPath(pathname, outletId);
|
|
118
|
+
return viewItem;
|
|
1148
119
|
}
|
|
1149
120
|
/**
|
|
1150
|
-
*
|
|
1151
|
-
* Returns both the matched view item and match metadata.
|
|
121
|
+
* Returns the matching view item and the match result for a given pathname.
|
|
1152
122
|
*/
|
|
1153
|
-
findViewItemByPath(pathname, outletId, mustBeIonRoute
|
|
123
|
+
findViewItemByPath(pathname, outletId, mustBeIonRoute) {
|
|
1154
124
|
let viewItem;
|
|
1155
|
-
let match
|
|
125
|
+
let match;
|
|
1156
126
|
let viewStack;
|
|
1157
|
-
// Capture stored parent paths for use in nested matchView/matchDefaultRoute functions
|
|
1158
|
-
const storedParentPaths = this.outletParentPaths;
|
|
1159
127
|
if (outletId) {
|
|
1160
|
-
viewStack =
|
|
128
|
+
viewStack = this.getViewItemsForOutlet(outletId);
|
|
1161
129
|
viewStack.some(matchView);
|
|
1162
|
-
if (!viewItem
|
|
130
|
+
if (!viewItem) {
|
|
1163
131
|
viewStack.some(matchDefaultRoute);
|
|
132
|
+
}
|
|
1164
133
|
}
|
|
1165
134
|
else {
|
|
1166
|
-
const viewItems =
|
|
135
|
+
const viewItems = this.getAllViewItems();
|
|
1167
136
|
viewItems.some(matchView);
|
|
1168
|
-
if (!viewItem
|
|
137
|
+
if (!viewItem) {
|
|
1169
138
|
viewItems.some(matchDefaultRoute);
|
|
139
|
+
}
|
|
1170
140
|
}
|
|
1171
|
-
// If we still have not found a view item for this outlet, try to find a matching
|
|
1172
|
-
// view item across all outlets and adopt it into the current outlet. This helps
|
|
1173
|
-
// recover when an outlet remounts and receives a new id, leaving views associated
|
|
1174
|
-
// with the previous outlet id.
|
|
1175
|
-
// Do not adopt across outlets; if we didn't find a view for this outlet,
|
|
1176
|
-
// defer to route matching to create a new one.
|
|
1177
141
|
return { viewItem, match };
|
|
1178
|
-
/**
|
|
1179
|
-
* Matches a route path with dynamic parameters (e.g. /tabs/:id)
|
|
1180
|
-
*/
|
|
1181
142
|
function matchView(v) {
|
|
1182
|
-
var _a;
|
|
1183
|
-
if (mustBeIonRoute && !v.ionRoute)
|
|
1184
|
-
return false;
|
|
1185
|
-
const viewItemPath = v.routeData.childProps.path || '';
|
|
1186
|
-
// Skip unmounted catch-all wildcard views. After back navigation unmounts
|
|
1187
|
-
// a wildcard view, it should not be reused for subsequent navigations.
|
|
1188
|
-
// A fresh wildcard view will be created by createViewItem when needed.
|
|
1189
|
-
if ((viewItemPath === '*' || viewItemPath === '/*') && !v.mount)
|
|
143
|
+
var _a, _b;
|
|
144
|
+
if (mustBeIonRoute && !v.ionRoute) {
|
|
1190
145
|
return false;
|
|
1191
|
-
const isIndexRoute = !!v.routeData.childProps.index;
|
|
1192
|
-
const previousMatch = (_a = v.routeData) === null || _a === void 0 ? void 0 : _a.match;
|
|
1193
|
-
const outletParentPath = storedParentPaths.get(v.outletId);
|
|
1194
|
-
const result = v.reactElement ? matchComponent$1(v.reactElement, pathname, false, outletParentPath) : null;
|
|
1195
|
-
if (!result) {
|
|
1196
|
-
const indexMatch = resolveIndexRouteMatch(v, pathname, outletParentPath);
|
|
1197
|
-
if (indexMatch) {
|
|
1198
|
-
match = indexMatch;
|
|
1199
|
-
viewItem = v;
|
|
1200
|
-
return true;
|
|
1201
|
-
}
|
|
1202
|
-
// Empty path routes (path="") should match when the pathname matches the
|
|
1203
|
-
// outlet's parent path exactly (no remaining segments). matchComponent doesn't
|
|
1204
|
-
// handle this because it lacks parent path context. Without this check, a
|
|
1205
|
-
// catch-all * view item (which matches any pathname) would be incorrectly
|
|
1206
|
-
// returned instead of the empty path route on back navigation.
|
|
1207
|
-
if (viewItemPath === '' && !isIndexRoute && outletParentPath) {
|
|
1208
|
-
const normalizedParent = normalizePathnameForComparison(outletParentPath);
|
|
1209
|
-
const normalizedPathname = normalizePathnameForComparison(pathname);
|
|
1210
|
-
if (normalizedPathname === normalizedParent) {
|
|
1211
|
-
match = createDefaultMatch(pathname, v.routeData.childProps);
|
|
1212
|
-
viewItem = v;
|
|
1213
|
-
return true;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
146
|
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
if (isParameterRoute && !isSamePath) {
|
|
1231
|
-
if (isWildcardRoute) {
|
|
1232
|
-
const isSameBase = result.pathnameBase === (previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.pathnameBase);
|
|
1233
|
-
if (isSameBase) {
|
|
1234
|
-
match = result;
|
|
1235
|
-
viewItem = v;
|
|
1236
|
-
return true;
|
|
1237
|
-
}
|
|
1238
|
-
}
|
|
1239
|
-
return false;
|
|
1240
|
-
}
|
|
1241
|
-
// For routes without params, or when navigating to the exact same path,
|
|
1242
|
-
// or when there's no previous match, reuse the view item
|
|
1243
|
-
if (!hasParams || isSamePath || !previousMatch) {
|
|
1244
|
-
match = result;
|
|
147
|
+
match = matchPath({
|
|
148
|
+
pathname,
|
|
149
|
+
componentProps: v.routeData.childProps,
|
|
150
|
+
});
|
|
151
|
+
if (match) {
|
|
152
|
+
/**
|
|
153
|
+
* Even though we have a match from react-router, we do not know if the match
|
|
154
|
+
* is for this specific view item.
|
|
155
|
+
*
|
|
156
|
+
* To validate this, we need to check if the path and url match the view item's route data.
|
|
157
|
+
*/
|
|
158
|
+
const hasParameter = match.path.includes(':');
|
|
159
|
+
if (!hasParameter || (hasParameter && match.url === ((_b = (_a = v.routeData) === null || _a === void 0 ? void 0 : _a.match) === null || _b === void 0 ? void 0 : _b.url))) {
|
|
1245
160
|
viewItem = v;
|
|
1246
161
|
return true;
|
|
1247
162
|
}
|
|
1248
|
-
// For pure wildcard routes (without : params), compare pathnameBase to allow
|
|
1249
|
-
// child path changes while preserving the parent view. This handles container
|
|
1250
|
-
// routes like /tabs/* where switching between /tabs/tab1 and /tabs/tab2
|
|
1251
|
-
// should reuse the same ViewItem.
|
|
1252
|
-
if (isWildcardRoute && !isParameterRoute) {
|
|
1253
|
-
const isSameBase = result.pathnameBase === (previousMatch === null || previousMatch === void 0 ? void 0 : previousMatch.pathnameBase);
|
|
1254
|
-
if (isSameBase) {
|
|
1255
|
-
match = result;
|
|
1256
|
-
viewItem = v;
|
|
1257
|
-
return true;
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
163
|
}
|
|
1261
164
|
return false;
|
|
1262
165
|
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Matches a view with no path prop (default fallback route) or index route.
|
|
1265
|
-
*/
|
|
1266
166
|
function matchDefaultRoute(v) {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
const isDefaultRoute = childProps.path === undefined || childProps.path === '';
|
|
1270
|
-
const isIndexRoute = !!childProps.index;
|
|
1271
|
-
if (isIndexRoute) {
|
|
1272
|
-
const outletParentPath = storedParentPaths.get(v.outletId);
|
|
1273
|
-
const indexMatch = resolveIndexRouteMatch(v, pathname, outletParentPath);
|
|
1274
|
-
if (indexMatch) {
|
|
1275
|
-
match = indexMatch;
|
|
1276
|
-
viewItem = v;
|
|
1277
|
-
return true;
|
|
1278
|
-
}
|
|
1279
|
-
return false;
|
|
1280
|
-
}
|
|
1281
|
-
// For empty path routes, only match if we're at the same level as when the view was created.
|
|
1282
|
-
// This prevents an empty path view item from being reused for different routes.
|
|
1283
|
-
if (isDefaultRoute) {
|
|
1284
|
-
const previousPathnameBase = ((_b = (_a = v.routeData) === null || _a === void 0 ? void 0 : _a.match) === null || _b === void 0 ? void 0 : _b.pathnameBase) || '';
|
|
1285
|
-
const normalizedBase = normalizePathnameForComparison(previousPathnameBase);
|
|
1286
|
-
const normalizedPathname = normalizePathnameForComparison(pathname);
|
|
1287
|
-
if (normalizedPathname !== normalizedBase) {
|
|
1288
|
-
return false;
|
|
1289
|
-
}
|
|
167
|
+
// try to find a route that doesn't have a path or from prop, that will be our default route
|
|
168
|
+
if (!v.routeData.childProps.path && !v.routeData.childProps.from) {
|
|
1290
169
|
match = {
|
|
170
|
+
path: pathname,
|
|
171
|
+
url: pathname,
|
|
172
|
+
isExact: true,
|
|
1291
173
|
params: {},
|
|
1292
|
-
pathname,
|
|
1293
|
-
pathnameBase: pathname === '' ? '/' : pathname,
|
|
1294
|
-
pattern: {
|
|
1295
|
-
path: '',
|
|
1296
|
-
caseSensitive: (_c = childProps.caseSensitive) !== null && _c !== void 0 ? _c : false,
|
|
1297
|
-
end: true,
|
|
1298
|
-
},
|
|
1299
174
|
};
|
|
1300
175
|
viewItem = v;
|
|
1301
176
|
return true;
|
|
@@ -1304,40 +179,11 @@ class ReactRouterViewStack extends ViewStacks {
|
|
|
1304
179
|
}
|
|
1305
180
|
}
|
|
1306
181
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
var _a;
|
|
1312
|
-
const routeProps = (_a = node === null || node === void 0 ? void 0 : node.props) !== null && _a !== void 0 ? _a : {};
|
|
1313
|
-
const routePath = routeProps.path;
|
|
1314
|
-
let pathnameToMatch;
|
|
1315
|
-
if (parentPath && routePath && !routePath.startsWith('/')) {
|
|
1316
|
-
// When parent path is known, compute exact relative pathname
|
|
1317
|
-
// instead of using the tail-slice heuristic
|
|
1318
|
-
const relative = pathname.startsWith(parentPath)
|
|
1319
|
-
? pathname.slice(parentPath.length).replace(/^\//, '')
|
|
1320
|
-
: pathname;
|
|
1321
|
-
pathnameToMatch = relative;
|
|
1322
|
-
}
|
|
1323
|
-
else {
|
|
1324
|
-
pathnameToMatch = derivePathnameToMatch(pathname, routePath);
|
|
1325
|
-
}
|
|
1326
|
-
const match = matchPath({
|
|
1327
|
-
pathname: pathnameToMatch,
|
|
1328
|
-
componentProps: routeProps,
|
|
182
|
+
function matchComponent$1(node, pathname) {
|
|
183
|
+
return matchPath({
|
|
184
|
+
pathname,
|
|
185
|
+
componentProps: node.props,
|
|
1329
186
|
});
|
|
1330
|
-
if (match || !allowFallback) {
|
|
1331
|
-
return match;
|
|
1332
|
-
}
|
|
1333
|
-
const isIndexRoute = !!routeProps.index;
|
|
1334
|
-
if (isIndexRoute) {
|
|
1335
|
-
return createDefaultMatch(pathname, routeProps);
|
|
1336
|
-
}
|
|
1337
|
-
if (!routePath || routePath === '') {
|
|
1338
|
-
return createDefaultMatch(pathname, routeProps);
|
|
1339
|
-
}
|
|
1340
|
-
return null;
|
|
1341
187
|
}
|
|
1342
188
|
|
|
1343
189
|
function clonePageElement(leavingViewHtml) {
|
|
@@ -1362,37 +208,7 @@ function clonePageElement(leavingViewHtml) {
|
|
|
1362
208
|
return undefined;
|
|
1363
209
|
}
|
|
1364
210
|
|
|
1365
|
-
|
|
1366
|
-
* `StackManager` is responsible for managing page transitions, keeping track
|
|
1367
|
-
* of views (pages), and ensuring that navigation behaves like native apps —
|
|
1368
|
-
* particularly with animations and swipe gestures.
|
|
1369
|
-
*/
|
|
1370
|
-
/**
|
|
1371
|
-
* Delay in milliseconds before unmounting a view after a transition completes.
|
|
1372
|
-
* This ensures the page transition animation finishes before the view is removed.
|
|
1373
|
-
*/
|
|
1374
|
-
const VIEW_UNMOUNT_DELAY_MS = 250;
|
|
1375
|
-
/**
|
|
1376
|
-
* Delay (ms) to wait for an IonPage to mount before proceeding with a
|
|
1377
|
-
* page transition. Only container routes (nested outlets with no direct
|
|
1378
|
-
* IonPage) actually hit this timeout; normal routes clear it early via
|
|
1379
|
-
* registerIonPage, so a larger value here doesn't affect the happy path.
|
|
1380
|
-
*/
|
|
1381
|
-
const ION_PAGE_WAIT_TIMEOUT_MS = 300;
|
|
1382
|
-
const isViewVisible = (el) => !el.classList.contains('ion-page-invisible') && !el.classList.contains('ion-page-hidden') && el.style.visibility !== 'hidden';
|
|
1383
|
-
const hideIonPageElement = (element) => {
|
|
1384
|
-
if (element) {
|
|
1385
|
-
element.classList.add('ion-page-hidden');
|
|
1386
|
-
element.setAttribute('aria-hidden', 'true');
|
|
1387
|
-
}
|
|
1388
|
-
};
|
|
1389
|
-
const showIonPageElement = (element) => {
|
|
1390
|
-
if (element) {
|
|
1391
|
-
element.style.removeProperty('visibility');
|
|
1392
|
-
element.classList.remove('ion-page-hidden');
|
|
1393
|
-
element.removeAttribute('aria-hidden');
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
211
|
+
const isViewVisible = (el) => !el.classList.contains('ion-page-invisible') && !el.classList.contains('ion-page-hidden');
|
|
1396
212
|
class StackManager extends React.PureComponent {
|
|
1397
213
|
constructor(props) {
|
|
1398
214
|
super(props);
|
|
@@ -1401,540 +217,14 @@ class StackManager extends React.PureComponent {
|
|
|
1401
217
|
isInOutlet: () => true,
|
|
1402
218
|
};
|
|
1403
219
|
this.pendingPageTransition = false;
|
|
1404
|
-
this.waitingForIonPage = false;
|
|
1405
|
-
/** Tracks whether the component is mounted to guard async transition paths. */
|
|
1406
|
-
this._isMounted = false;
|
|
1407
|
-
/** In-flight requestAnimationFrame IDs from transitionPage, cancelled on unmount. */
|
|
1408
|
-
this.transitionRafIds = [];
|
|
1409
|
-
this.outletMountPath = undefined;
|
|
1410
|
-
/**
|
|
1411
|
-
* Whether this outlet is at the root level (no parent route matches).
|
|
1412
|
-
* Derived from UNSAFE_RouteContext in render() — empty matches means root.
|
|
1413
|
-
*/
|
|
1414
|
-
this.isRootOutlet = true;
|
|
1415
220
|
this.registerIonPage = this.registerIonPage.bind(this);
|
|
1416
221
|
this.transitionPage = this.transitionPage.bind(this);
|
|
1417
222
|
this.handlePageTransition = this.handlePageTransition.bind(this);
|
|
1418
|
-
this.id =
|
|
223
|
+
this.id = generateId('routerOutlet');
|
|
1419
224
|
this.prevProps = undefined;
|
|
1420
225
|
this.skipTransition = false;
|
|
1421
226
|
}
|
|
1422
|
-
/**
|
|
1423
|
-
* Determines the parent path for nested routing in React Router 6.
|
|
1424
|
-
*
|
|
1425
|
-
* When the mount path is known (seeded from UNSAFE_RouteContext), returns
|
|
1426
|
-
* it directly — no iterative discovery needed. The computeParentPath
|
|
1427
|
-
* fallback only runs for root outlets where RouteContext doesn't provide
|
|
1428
|
-
* a parent match.
|
|
1429
|
-
*/
|
|
1430
|
-
getParentPath() {
|
|
1431
|
-
const currentPathname = this.props.routeInfo.pathname;
|
|
1432
|
-
// Prevent out-of-scope outlets from adopting unrelated routes.
|
|
1433
|
-
// Uses segment-aware comparison: /tabs-secondary must NOT match /tabs scope.
|
|
1434
|
-
if (this.outletMountPath && !isPathnameInScope(currentPathname, this.outletMountPath)) {
|
|
1435
|
-
return undefined;
|
|
1436
|
-
}
|
|
1437
|
-
// Fast path: mount path is known from RouteContext. The parent path IS the
|
|
1438
|
-
// mount path — no need to run the iterative computeParentPath algorithm.
|
|
1439
|
-
if (this.outletMountPath && !this.isRootOutlet) {
|
|
1440
|
-
return this.outletMountPath;
|
|
1441
|
-
}
|
|
1442
|
-
// Fallback: root outlet or mount path not yet seeded. Run the full
|
|
1443
|
-
// computeParentPath algorithm to discover the parent depth.
|
|
1444
|
-
if (this.ionRouterOutlet) {
|
|
1445
|
-
const routeChildren = extractRouteChildren(this.ionRouterOutlet.props.children);
|
|
1446
|
-
const { hasRelativeRoutes, hasIndexRoute, hasWildcardRoute } = analyzeRouteChildren(routeChildren);
|
|
1447
|
-
if (!this.isRootOutlet || hasRelativeRoutes || hasIndexRoute) {
|
|
1448
|
-
const result = computeParentPath({
|
|
1449
|
-
currentPathname,
|
|
1450
|
-
outletMountPath: this.outletMountPath,
|
|
1451
|
-
routeChildren,
|
|
1452
|
-
hasRelativeRoutes,
|
|
1453
|
-
hasIndexRoute,
|
|
1454
|
-
hasWildcardRoute,
|
|
1455
|
-
});
|
|
1456
|
-
if (result.outletMountPath && !this.outletMountPath) {
|
|
1457
|
-
this.outletMountPath = result.outletMountPath;
|
|
1458
|
-
}
|
|
1459
|
-
return result.parentPath;
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
return this.outletMountPath;
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* Finds the entering and leaving view items, handling redirect cases.
|
|
1466
|
-
*/
|
|
1467
|
-
findViewItems(routeInfo) {
|
|
1468
|
-
const enteringViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id);
|
|
1469
|
-
let leavingViewItem = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id);
|
|
1470
|
-
// Try to find leaving view by previous pathname
|
|
1471
|
-
if (!leavingViewItem && routeInfo.prevRouteLastPathname) {
|
|
1472
|
-
leavingViewItem = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id);
|
|
1473
|
-
}
|
|
1474
|
-
// For redirects where entering === leaving, find the actual previous view
|
|
1475
|
-
if (enteringViewItem &&
|
|
1476
|
-
leavingViewItem &&
|
|
1477
|
-
enteringViewItem === leavingViewItem &&
|
|
1478
|
-
routeInfo.routeAction === 'replace' &&
|
|
1479
|
-
routeInfo.prevRouteLastPathname) {
|
|
1480
|
-
const actualLeavingView = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id);
|
|
1481
|
-
if (actualLeavingView && actualLeavingView !== enteringViewItem) {
|
|
1482
|
-
leavingViewItem = actualLeavingView;
|
|
1483
|
-
}
|
|
1484
|
-
}
|
|
1485
|
-
// Handle redirect scenario with no leaving view
|
|
1486
|
-
if (enteringViewItem &&
|
|
1487
|
-
!leavingViewItem &&
|
|
1488
|
-
routeInfo.routeAction === 'replace' &&
|
|
1489
|
-
routeInfo.prevRouteLastPathname) {
|
|
1490
|
-
const actualLeavingView = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id);
|
|
1491
|
-
if (actualLeavingView && actualLeavingView !== enteringViewItem) {
|
|
1492
|
-
leavingViewItem = actualLeavingView;
|
|
1493
|
-
}
|
|
1494
|
-
}
|
|
1495
|
-
return { enteringViewItem, leavingViewItem };
|
|
1496
|
-
}
|
|
1497
|
-
shouldUnmountLeavingView(routeInfo, enteringViewItem, leavingViewItem) {
|
|
1498
|
-
var _a, _b, _c, _d;
|
|
1499
|
-
if (!leavingViewItem) {
|
|
1500
|
-
return false;
|
|
1501
|
-
}
|
|
1502
|
-
if (routeInfo.routeAction === 'replace') {
|
|
1503
|
-
const enteringRoutePath = (_b = (_a = enteringViewItem === null || enteringViewItem === void 0 ? void 0 : enteringViewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
1504
|
-
const leavingRoutePath = (_d = (_c = leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.reactElement) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.path;
|
|
1505
|
-
// Never unmount root path - needed for back navigation
|
|
1506
|
-
if (leavingRoutePath === '/' || leavingRoutePath === '') {
|
|
1507
|
-
return false;
|
|
1508
|
-
}
|
|
1509
|
-
if (enteringRoutePath && leavingRoutePath) {
|
|
1510
|
-
const getParentPath = (path) => {
|
|
1511
|
-
const normalized = path.replace(/\/\*$/, '');
|
|
1512
|
-
const lastSlash = normalized.lastIndexOf('/');
|
|
1513
|
-
return lastSlash > 0 ? normalized.substring(0, lastSlash) : '/';
|
|
1514
|
-
};
|
|
1515
|
-
const enteringParent = getParentPath(enteringRoutePath);
|
|
1516
|
-
const leavingParent = getParentPath(leavingRoutePath);
|
|
1517
|
-
// Unmount if routes are siblings or entering is a child of leaving (redirect)
|
|
1518
|
-
const areSiblings = enteringParent === leavingParent && enteringParent !== '/';
|
|
1519
|
-
const isChildRedirect = enteringRoutePath.startsWith(leavingRoutePath) ||
|
|
1520
|
-
(leavingRoutePath.endsWith('/*') && enteringRoutePath.startsWith(leavingRoutePath.slice(0, -2)));
|
|
1521
|
-
return areSiblings || isChildRedirect;
|
|
1522
|
-
}
|
|
1523
|
-
return false;
|
|
1524
|
-
}
|
|
1525
|
-
// For non-replace actions, only unmount for back navigation
|
|
1526
|
-
const isForwardPush = routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'forward';
|
|
1527
|
-
if (!isForwardPush && routeInfo.routeDirection !== 'none' && enteringViewItem !== leavingViewItem) {
|
|
1528
|
-
return true;
|
|
1529
|
-
}
|
|
1530
|
-
return false;
|
|
1531
|
-
}
|
|
1532
|
-
/**
|
|
1533
|
-
* Handles out-of-scope outlet. Returns true if transition should be aborted.
|
|
1534
|
-
*/
|
|
1535
|
-
handleOutOfScopeOutlet(routeInfo) {
|
|
1536
|
-
if (!this.outletMountPath || isPathnameInScope(routeInfo.pathname, this.outletMountPath)) {
|
|
1537
|
-
return false;
|
|
1538
|
-
}
|
|
1539
|
-
if (this.outOfScopeUnmountTimeout) {
|
|
1540
|
-
clearTimeout(this.outOfScopeUnmountTimeout);
|
|
1541
|
-
this.outOfScopeUnmountTimeout = undefined;
|
|
1542
|
-
}
|
|
1543
|
-
// Remove view items from the stack but do NOT apply ion-page-hidden.
|
|
1544
|
-
// ion-page-hidden sets display:none which immediately removes content
|
|
1545
|
-
// from the layout, causing the parent outlet's leaving page to flash
|
|
1546
|
-
// blank during its transition animation (issue #25477).
|
|
1547
|
-
//
|
|
1548
|
-
// Removing from the stack triggers React reconciliation via forceUpdate,
|
|
1549
|
-
// which removes the DOM elements. React batches this re-render after all
|
|
1550
|
-
// componentDidUpdate calls in the current cycle, so the parent outlet's
|
|
1551
|
-
// commit() captures the current DOM state (with content visible) before
|
|
1552
|
-
// React processes the removal. The compositor's cached layer is unaffected
|
|
1553
|
-
// by subsequent DOM changes during the animation.
|
|
1554
|
-
const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
|
|
1555
|
-
allViewsInOutlet.forEach((viewItem) => {
|
|
1556
|
-
this.context.unMountViewItem(viewItem);
|
|
1557
|
-
});
|
|
1558
|
-
this.forceUpdate();
|
|
1559
|
-
return true;
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* Handles nested outlet with relative routes but no parent path. Returns true to abort.
|
|
1563
|
-
*/
|
|
1564
|
-
handleOutOfContextNestedOutlet(parentPath, leavingViewItem) {
|
|
1565
|
-
var _a;
|
|
1566
|
-
if (this.isRootOutlet || parentPath !== undefined || !this.ionRouterOutlet) {
|
|
1567
|
-
return false;
|
|
1568
|
-
}
|
|
1569
|
-
const routesChildren = (_a = getRoutesChildren(this.ionRouterOutlet.props.children)) !== null && _a !== void 0 ? _a : this.ionRouterOutlet.props.children;
|
|
1570
|
-
const routeChildren = React.Children.toArray(routesChildren).filter((child) => React.isValidElement(child) && (child.type === Route || child.type === IonRoute));
|
|
1571
|
-
const hasRelativeRoutes = routeChildren.some((route) => {
|
|
1572
|
-
const path = route.props.path;
|
|
1573
|
-
return path && !path.startsWith('/') && path !== '*';
|
|
1574
|
-
});
|
|
1575
|
-
if (hasRelativeRoutes) {
|
|
1576
|
-
hideIonPageElement(leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.ionPageElement);
|
|
1577
|
-
if (leavingViewItem) {
|
|
1578
|
-
leavingViewItem.mount = false;
|
|
1579
|
-
}
|
|
1580
|
-
this.forceUpdate();
|
|
1581
|
-
return true;
|
|
1582
|
-
}
|
|
1583
|
-
return false;
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Handles nested outlet with no matching route. Returns true to abort.
|
|
1587
|
-
*/
|
|
1588
|
-
handleNoMatchingRoute(enteringRoute, enteringViewItem, leavingViewItem) {
|
|
1589
|
-
if (this.isRootOutlet || enteringRoute || enteringViewItem) {
|
|
1590
|
-
return false;
|
|
1591
|
-
}
|
|
1592
|
-
hideIonPageElement(leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.ionPageElement);
|
|
1593
|
-
if (leavingViewItem) {
|
|
1594
|
-
leavingViewItem.mount = false;
|
|
1595
|
-
}
|
|
1596
|
-
this.forceUpdate();
|
|
1597
|
-
return true;
|
|
1598
|
-
}
|
|
1599
|
-
/**
|
|
1600
|
-
* Handles transition when entering view has ion-page element ready.
|
|
1601
|
-
*/
|
|
1602
|
-
handleReadyEnteringView(routeInfo, enteringViewItem, leavingViewItem, shouldUnmountLeavingViewItem) {
|
|
1603
|
-
var _a, _b;
|
|
1604
|
-
const routePath = (_b = (_a = enteringViewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
1605
|
-
const isParameterizedRoute = routePath ? routePath.includes(':') : false;
|
|
1606
|
-
const isWildcardContainerRoute = routePath ? routePath.endsWith('/*') : false;
|
|
1607
|
-
// Handle same-view transitions (parameterized routes like /user/:id or container routes like /tabs/*)
|
|
1608
|
-
// When entering === leaving, the view is already visible - skip transition to prevent flash
|
|
1609
|
-
if (enteringViewItem === leavingViewItem) {
|
|
1610
|
-
if (isParameterizedRoute || isWildcardContainerRoute) {
|
|
1611
|
-
const updatedMatch = matchComponent(enteringViewItem.reactElement, routeInfo.pathname, true, this.outletMountPath);
|
|
1612
|
-
if (updatedMatch) {
|
|
1613
|
-
enteringViewItem.routeData.match = updatedMatch;
|
|
1614
|
-
}
|
|
1615
|
-
const enteringEl = enteringViewItem.ionPageElement;
|
|
1616
|
-
if (enteringEl) {
|
|
1617
|
-
showIonPageElement(enteringEl);
|
|
1618
|
-
enteringEl.classList.remove('ion-page-invisible');
|
|
1619
|
-
}
|
|
1620
|
-
this.forceUpdate();
|
|
1621
|
-
return;
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
// For wildcard container routes, check if we're navigating within the same container.
|
|
1625
|
-
// If both the current pathname and the previous pathname match the same container route,
|
|
1626
|
-
// skip the transition - the nested outlet will handle the actual page change.
|
|
1627
|
-
// This handles cases where leavingViewItem lookup fails (e.g., no IonPage wrapper).
|
|
1628
|
-
if (isWildcardContainerRoute && routeInfo.lastPathname) {
|
|
1629
|
-
// routePath is guaranteed to exist since isWildcardContainerRoute checks routePath?.endsWith('/*')
|
|
1630
|
-
const containerBase = routePath.replace(/\/\*$/, '');
|
|
1631
|
-
const currentInContainer = routeInfo.pathname.startsWith(containerBase + '/') || routeInfo.pathname === containerBase;
|
|
1632
|
-
const previousInContainer = routeInfo.lastPathname.startsWith(containerBase + '/') || routeInfo.lastPathname === containerBase;
|
|
1633
|
-
if (currentInContainer && previousInContainer) {
|
|
1634
|
-
const updatedMatch = matchComponent(enteringViewItem.reactElement, routeInfo.pathname, true, this.outletMountPath);
|
|
1635
|
-
if (updatedMatch) {
|
|
1636
|
-
enteringViewItem.routeData.match = updatedMatch;
|
|
1637
|
-
}
|
|
1638
|
-
this.forceUpdate();
|
|
1639
|
-
return;
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
if (!leavingViewItem && this.props.routeInfo.prevRouteLastPathname) {
|
|
1643
|
-
leavingViewItem = this.context.findViewItemByPathname(this.props.routeInfo.prevRouteLastPathname, this.id);
|
|
1644
|
-
}
|
|
1645
|
-
// Re-mount views that were previously unmounted (e.g., navigating back to home)
|
|
1646
|
-
if (!enteringViewItem.mount) {
|
|
1647
|
-
enteringViewItem.mount = true;
|
|
1648
|
-
}
|
|
1649
|
-
// Check visibility state BEFORE showing entering view
|
|
1650
|
-
const enteringWasVisible = enteringViewItem.ionPageElement && isViewVisible(enteringViewItem.ionPageElement);
|
|
1651
|
-
const leavingIsHidden = leavingViewItem !== undefined && leavingViewItem.ionPageElement && !isViewVisible(leavingViewItem.ionPageElement);
|
|
1652
|
-
const currentTransition = {
|
|
1653
|
-
enteringId: enteringViewItem.id,
|
|
1654
|
-
leavingId: leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.id,
|
|
1655
|
-
};
|
|
1656
|
-
const isDuplicateTransition = leavingViewItem &&
|
|
1657
|
-
this.lastTransition &&
|
|
1658
|
-
this.lastTransition.leavingId &&
|
|
1659
|
-
this.lastTransition.enteringId === currentTransition.enteringId &&
|
|
1660
|
-
this.lastTransition.leavingId === currentTransition.leavingId;
|
|
1661
|
-
// Skip if transition already performed (e.g., via swipe gesture)
|
|
1662
|
-
if (enteringWasVisible && leavingIsHidden && isDuplicateTransition) {
|
|
1663
|
-
if (this.skipTransition &&
|
|
1664
|
-
shouldUnmountLeavingViewItem &&
|
|
1665
|
-
leavingViewItem &&
|
|
1666
|
-
enteringViewItem !== leavingViewItem) {
|
|
1667
|
-
leavingViewItem.mount = false;
|
|
1668
|
-
// Trigger ionViewDidLeave lifecycle for ViewLifeCycleManager cleanup
|
|
1669
|
-
this.transitionPage(routeInfo, enteringViewItem, leavingViewItem, 'back');
|
|
1670
|
-
}
|
|
1671
|
-
this.skipTransition = false;
|
|
1672
|
-
this.forceUpdate();
|
|
1673
|
-
return;
|
|
1674
|
-
}
|
|
1675
|
-
showIonPageElement(enteringViewItem.ionPageElement);
|
|
1676
|
-
// Handle duplicate transition or swipe gesture completion
|
|
1677
|
-
if (isDuplicateTransition || this.skipTransition) {
|
|
1678
|
-
if (this.skipTransition &&
|
|
1679
|
-
shouldUnmountLeavingViewItem &&
|
|
1680
|
-
leavingViewItem &&
|
|
1681
|
-
enteringViewItem !== leavingViewItem) {
|
|
1682
|
-
leavingViewItem.mount = false;
|
|
1683
|
-
// Re-fire ionViewDidLeave since gesture completed before mount=false was set
|
|
1684
|
-
this.transitionPage(routeInfo, enteringViewItem, leavingViewItem, 'back');
|
|
1685
|
-
}
|
|
1686
|
-
this.skipTransition = false;
|
|
1687
|
-
this.forceUpdate();
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
this.lastTransition = currentTransition;
|
|
1691
|
-
const shouldSkipAnimation = this.applySkipAnimationIfNeeded(enteringViewItem, leavingViewItem);
|
|
1692
|
-
this.transitionPage(routeInfo, enteringViewItem, leavingViewItem, undefined, false, shouldSkipAnimation);
|
|
1693
|
-
if (shouldUnmountLeavingViewItem && leavingViewItem && enteringViewItem !== leavingViewItem) {
|
|
1694
|
-
leavingViewItem.mount = false;
|
|
1695
|
-
this.handleLeavingViewUnmount(routeInfo, enteringViewItem, leavingViewItem);
|
|
1696
|
-
}
|
|
1697
|
-
// Clean up orphaned sibling views after replace actions (redirects)
|
|
1698
|
-
this.cleanupOrphanedSiblingViews(routeInfo, enteringViewItem, leavingViewItem);
|
|
1699
|
-
}
|
|
1700
|
-
/**
|
|
1701
|
-
* Handles leaving view unmount for replace actions.
|
|
1702
|
-
*/
|
|
1703
|
-
handleLeavingViewUnmount(routeInfo, enteringViewItem, leavingViewItem) {
|
|
1704
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1705
|
-
if (!leavingViewItem.ionPageElement) {
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
// Only replace actions unmount views; push/pop cache for navigation history
|
|
1709
|
-
if (routeInfo.routeAction !== 'replace') {
|
|
1710
|
-
return;
|
|
1711
|
-
}
|
|
1712
|
-
const enteringRoutePath = (_b = (_a = enteringViewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
1713
|
-
const leavingRoutePath = (_d = (_c = leavingViewItem.reactElement) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.path;
|
|
1714
|
-
const isEnteringContainerRoute = enteringRoutePath && enteringRoutePath.endsWith('/*');
|
|
1715
|
-
const isLeavingSpecificRoute = leavingRoutePath &&
|
|
1716
|
-
leavingRoutePath !== '' &&
|
|
1717
|
-
leavingRoutePath !== '*' &&
|
|
1718
|
-
!leavingRoutePath.endsWith('/*') &&
|
|
1719
|
-
!((_f = (_e = leavingViewItem.reactElement) === null || _e === void 0 ? void 0 : _e.props) === null || _f === void 0 ? void 0 : _f.index);
|
|
1720
|
-
// Skip removal for container-to-container transitions (e.g., /tabs/* → /settings/*).
|
|
1721
|
-
// These routes manage their own nested outlets; unmounting would disrupt child views.
|
|
1722
|
-
if (isEnteringContainerRoute && !isLeavingSpecificRoute) {
|
|
1723
|
-
return;
|
|
1724
|
-
}
|
|
1725
|
-
const viewToUnmount = leavingViewItem;
|
|
1726
|
-
setTimeout(() => {
|
|
1727
|
-
this.context.unMountViewItem(viewToUnmount);
|
|
1728
|
-
this.forceUpdate();
|
|
1729
|
-
}, VIEW_UNMOUNT_DELAY_MS);
|
|
1730
|
-
}
|
|
1731
|
-
/**
|
|
1732
|
-
* Cleans up orphaned sibling views after replace actions or push-to-container navigations.
|
|
1733
|
-
*/
|
|
1734
|
-
cleanupOrphanedSiblingViews(routeInfo, enteringViewItem, leavingViewItem) {
|
|
1735
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
1736
|
-
const enteringRoutePath = (_b = (_a = enteringViewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.path;
|
|
1737
|
-
if (!enteringRoutePath) {
|
|
1738
|
-
return;
|
|
1739
|
-
}
|
|
1740
|
-
const leavingRoutePath = (_d = (_c = leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.reactElement) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.path;
|
|
1741
|
-
const isContainerRoute = (path) => path === null || path === void 0 ? void 0 : path.endsWith('/*');
|
|
1742
|
-
const isReplaceAction = routeInfo.routeAction === 'replace';
|
|
1743
|
-
const isPushToContainer = routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'none' && isContainerRoute(enteringRoutePath);
|
|
1744
|
-
if (!isReplaceAction && !isPushToContainer) {
|
|
1745
|
-
return;
|
|
1746
|
-
}
|
|
1747
|
-
// Skip cleanup for tab switches
|
|
1748
|
-
const isSameView = enteringViewItem === leavingViewItem;
|
|
1749
|
-
const isSameContainerRoute = isContainerRoute(enteringRoutePath) && leavingRoutePath === enteringRoutePath;
|
|
1750
|
-
const isNavigatingWithinContainer = isPushToContainer &&
|
|
1751
|
-
!leavingViewItem &&
|
|
1752
|
-
((_e = routeInfo.prevRouteLastPathname) === null || _e === void 0 ? void 0 : _e.startsWith(enteringRoutePath.replace(/\/\*$/, '')));
|
|
1753
|
-
if (isSameView || isSameContainerRoute || isNavigatingWithinContainer) {
|
|
1754
|
-
return;
|
|
1755
|
-
}
|
|
1756
|
-
const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
|
|
1757
|
-
const areSiblingRoutes = (path1, path2) => {
|
|
1758
|
-
const path1IsRelative = !path1.startsWith('/');
|
|
1759
|
-
const path2IsRelative = !path2.startsWith('/');
|
|
1760
|
-
if (path1IsRelative && path2IsRelative) {
|
|
1761
|
-
const path1Depth = path1.replace(/\/\*$/, '').split('/').filter(Boolean).length;
|
|
1762
|
-
const path2Depth = path2.replace(/\/\*$/, '').split('/').filter(Boolean).length;
|
|
1763
|
-
return path1Depth === path2Depth && path1Depth <= 1;
|
|
1764
|
-
}
|
|
1765
|
-
const getParent = (path) => {
|
|
1766
|
-
const normalized = path.replace(/\/\*$/, '');
|
|
1767
|
-
const lastSlash = normalized.lastIndexOf('/');
|
|
1768
|
-
return lastSlash > 0 ? normalized.substring(0, lastSlash) : '/';
|
|
1769
|
-
};
|
|
1770
|
-
return getParent(path1) === getParent(path2);
|
|
1771
|
-
};
|
|
1772
|
-
for (const viewItem of allViewsInOutlet) {
|
|
1773
|
-
const viewRoutePath = (_g = (_f = viewItem.reactElement) === null || _f === void 0 ? void 0 : _f.props) === null || _g === void 0 ? void 0 : _g.path;
|
|
1774
|
-
const shouldSkip = viewItem.id === enteringViewItem.id ||
|
|
1775
|
-
(leavingViewItem && viewItem.id === leavingViewItem.id) ||
|
|
1776
|
-
!viewItem.mount ||
|
|
1777
|
-
!viewRoutePath ||
|
|
1778
|
-
(viewRoutePath.endsWith('/*') && enteringRoutePath.endsWith('/*'));
|
|
1779
|
-
if (shouldSkip) {
|
|
1780
|
-
continue;
|
|
1781
|
-
}
|
|
1782
|
-
if (areSiblingRoutes(enteringRoutePath, viewRoutePath)) {
|
|
1783
|
-
hideIonPageElement(viewItem.ionPageElement);
|
|
1784
|
-
viewItem.mount = false;
|
|
1785
|
-
const viewToRemove = viewItem;
|
|
1786
|
-
setTimeout(() => {
|
|
1787
|
-
this.context.unMountViewItem(viewToRemove);
|
|
1788
|
-
this.forceUpdate();
|
|
1789
|
-
}, VIEW_UNMOUNT_DELAY_MS);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
}
|
|
1793
|
-
/**
|
|
1794
|
-
* Determines whether to skip the transition animation and, if so, immediately
|
|
1795
|
-
* hides the leaving view with inline `visibility:hidden`.
|
|
1796
|
-
*
|
|
1797
|
-
* Skips transitions only for outlets nested inside a parent IonPage's content
|
|
1798
|
-
* area (i.e., an ion-content sits between the outlet and the .ion-page). These
|
|
1799
|
-
* outlets render child pages inside a parent page's scrollable area, and the MD
|
|
1800
|
-
* animation shows both entering and leaving pages simultaneously — causing text
|
|
1801
|
-
* overlap and nested scrollbars. Standard page-level outlets (tabs, routing,
|
|
1802
|
-
* swipe-to-go-back) animate normally even though they sit inside a framework-
|
|
1803
|
-
* managed .ion-page wrapper from the parent outlet's view stack.
|
|
1804
|
-
*
|
|
1805
|
-
* Uses inline visibility:hidden rather than ion-page-hidden class because
|
|
1806
|
-
* core's beforeTransition() removes ion-page-hidden via setPageHidden().
|
|
1807
|
-
* Inline visibility:hidden survives that removal, keeping the page hidden
|
|
1808
|
-
* until React unmounts it after ionViewDidLeave fires. Unlike display:none,
|
|
1809
|
-
* visibility:hidden preserves element geometry so commit() animations
|
|
1810
|
-
* can resolve normally.
|
|
1811
|
-
*/
|
|
1812
|
-
applySkipAnimationIfNeeded(enteringViewItem, leavingViewItem) {
|
|
1813
|
-
var _a, _b;
|
|
1814
|
-
// Only skip for outlets genuinely nested inside a page's content area.
|
|
1815
|
-
// Walk from the outlet up to the nearest .ion-page; if an ion-content
|
|
1816
|
-
// sits in between, the outlet is inside scrollable page content and
|
|
1817
|
-
// animating would cause overlapping pages with duplicate scrollbars.
|
|
1818
|
-
let isInsidePageContent = false;
|
|
1819
|
-
let el = (_b = (_a = this.routerOutletElement) === null || _a === void 0 ? void 0 : _a.parentElement) !== null && _b !== void 0 ? _b : null;
|
|
1820
|
-
while (el) {
|
|
1821
|
-
if (el.classList.contains('ion-page'))
|
|
1822
|
-
break;
|
|
1823
|
-
if (el.tagName === 'ION-CONTENT') {
|
|
1824
|
-
isInsidePageContent = true;
|
|
1825
|
-
break;
|
|
1826
|
-
}
|
|
1827
|
-
el = el.parentElement;
|
|
1828
|
-
}
|
|
1829
|
-
const shouldSkip = isInsidePageContent && !!leavingViewItem && enteringViewItem !== leavingViewItem;
|
|
1830
|
-
if (shouldSkip && (leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.ionPageElement)) {
|
|
1831
|
-
leavingViewItem.ionPageElement.style.setProperty('visibility', 'hidden');
|
|
1832
|
-
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
|
|
1833
|
-
}
|
|
1834
|
-
return shouldSkip;
|
|
1835
|
-
}
|
|
1836
|
-
/**
|
|
1837
|
-
* Handles entering view with no ion-page element yet (waiting for render).
|
|
1838
|
-
*/
|
|
1839
|
-
handleWaitingForIonPage(routeInfo, enteringViewItem, leavingViewItem, shouldUnmountLeavingViewItem) {
|
|
1840
|
-
var _a, _b;
|
|
1841
|
-
const enteringRouteElement = (_b = (_a = enteringViewItem.reactElement) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.element;
|
|
1842
|
-
// Handle Navigate components (they never render an IonPage)
|
|
1843
|
-
if (isNavigateElement(enteringRouteElement)) {
|
|
1844
|
-
this.waitingForIonPage = false;
|
|
1845
|
-
if (this.ionPageWaitTimeout) {
|
|
1846
|
-
clearTimeout(this.ionPageWaitTimeout);
|
|
1847
|
-
this.ionPageWaitTimeout = undefined;
|
|
1848
|
-
}
|
|
1849
|
-
this.pendingPageTransition = false;
|
|
1850
|
-
// Hide ALL other visible views in this outlet for Navigate redirects.
|
|
1851
|
-
// Same rationale as the timeout path: intermediate redirects can shift
|
|
1852
|
-
// the leaving view reference, leaving the original page visible.
|
|
1853
|
-
const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
|
|
1854
|
-
allViewsInOutlet.forEach((viewItem) => {
|
|
1855
|
-
if (viewItem.id !== enteringViewItem.id && viewItem.ionPageElement) {
|
|
1856
|
-
hideIonPageElement(viewItem.ionPageElement);
|
|
1857
|
-
}
|
|
1858
|
-
});
|
|
1859
|
-
// Don't unmount if entering and leaving are the same view item
|
|
1860
|
-
if (shouldUnmountLeavingViewItem && leavingViewItem && enteringViewItem !== leavingViewItem) {
|
|
1861
|
-
leavingViewItem.mount = false;
|
|
1862
|
-
}
|
|
1863
|
-
this.forceUpdate();
|
|
1864
|
-
return;
|
|
1865
|
-
}
|
|
1866
|
-
// Do not hide the leaving view here - wait until the entering view is ready.
|
|
1867
|
-
// Hiding the leaving view while the entering view is still mounting causes a flash
|
|
1868
|
-
// where both views are hidden/invisible simultaneously.
|
|
1869
|
-
// The leaving view will be hidden in transitionPage() after the entering view is visible.
|
|
1870
|
-
this.waitingForIonPage = true;
|
|
1871
|
-
if (this.ionPageWaitTimeout) {
|
|
1872
|
-
clearTimeout(this.ionPageWaitTimeout);
|
|
1873
|
-
}
|
|
1874
|
-
this.ionPageWaitTimeout = setTimeout(() => {
|
|
1875
|
-
var _a, _b;
|
|
1876
|
-
this.ionPageWaitTimeout = undefined;
|
|
1877
|
-
if (!this.waitingForIonPage) {
|
|
1878
|
-
return;
|
|
1879
|
-
}
|
|
1880
|
-
this.waitingForIonPage = false;
|
|
1881
|
-
const latestEnteringView = (_a = this.context.findViewItemByRouteInfo(routeInfo, this.id)) !== null && _a !== void 0 ? _a : enteringViewItem;
|
|
1882
|
-
const latestLeavingView = (_b = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id)) !== null && _b !== void 0 ? _b : leavingViewItem;
|
|
1883
|
-
if (latestEnteringView === null || latestEnteringView === void 0 ? void 0 : latestEnteringView.ionPageElement) {
|
|
1884
|
-
const shouldSkipAnimation = this.applySkipAnimationIfNeeded(latestEnteringView, latestLeavingView !== null && latestLeavingView !== void 0 ? latestLeavingView : undefined);
|
|
1885
|
-
this.transitionPage(routeInfo, latestEnteringView, latestLeavingView !== null && latestLeavingView !== void 0 ? latestLeavingView : undefined, undefined, false, shouldSkipAnimation);
|
|
1886
|
-
if (shouldUnmountLeavingViewItem && latestLeavingView && latestEnteringView !== latestLeavingView) {
|
|
1887
|
-
latestLeavingView.mount = false;
|
|
1888
|
-
// Call handleLeavingViewUnmount to ensure the view is properly removed
|
|
1889
|
-
this.handleLeavingViewUnmount(routeInfo, latestEnteringView, latestLeavingView);
|
|
1890
|
-
}
|
|
1891
|
-
this.forceUpdate();
|
|
1892
|
-
}
|
|
1893
|
-
else {
|
|
1894
|
-
/**
|
|
1895
|
-
* Timeout fired and entering view still has no ionPageElement.
|
|
1896
|
-
* This happens for container routes that render nested outlets without a direct IonPage.
|
|
1897
|
-
* Hide ALL other visible views in this outlet, not just the computed leaving view.
|
|
1898
|
-
* This handles cases where intermediate redirects (e.g., Navigate in nested routes)
|
|
1899
|
-
* change the leaving view reference, leaving the original page still visible.
|
|
1900
|
-
*/
|
|
1901
|
-
const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
|
|
1902
|
-
allViewsInOutlet.forEach((viewItem) => {
|
|
1903
|
-
if (viewItem.id !== latestEnteringView.id && viewItem.ionPageElement) {
|
|
1904
|
-
hideIonPageElement(viewItem.ionPageElement);
|
|
1905
|
-
}
|
|
1906
|
-
});
|
|
1907
|
-
this.forceUpdate();
|
|
1908
|
-
// Safety net: after forceUpdate triggers a React render cycle, check if
|
|
1909
|
-
// any pages in this outlet are stuck with ion-page-invisible. This can
|
|
1910
|
-
// happen when view lookup fails (e.g., wildcard-to-index transitions
|
|
1911
|
-
// where the view item gets corrupted). The forceUpdate above causes
|
|
1912
|
-
// React to render the correct component, but ion-page-invisible may
|
|
1913
|
-
// persist if no transition runs for that page.
|
|
1914
|
-
setTimeout(() => {
|
|
1915
|
-
if (!this._isMounted || !this.routerOutletElement)
|
|
1916
|
-
return;
|
|
1917
|
-
const stuckPages = this.routerOutletElement.querySelectorAll(':scope > .ion-page-invisible');
|
|
1918
|
-
stuckPages.forEach((page) => {
|
|
1919
|
-
page.classList.remove('ion-page-invisible');
|
|
1920
|
-
});
|
|
1921
|
-
}, ION_PAGE_WAIT_TIMEOUT_MS);
|
|
1922
|
-
}
|
|
1923
|
-
}, ION_PAGE_WAIT_TIMEOUT_MS);
|
|
1924
|
-
this.forceUpdate();
|
|
1925
|
-
}
|
|
1926
|
-
/**
|
|
1927
|
-
* Gets the route info to use for finding views during swipe-to-go-back gestures.
|
|
1928
|
-
* This pattern is used in multiple places in setupRouterOutlet.
|
|
1929
|
-
*/
|
|
1930
|
-
getSwipeBackRouteInfo() {
|
|
1931
|
-
const { routeInfo } = this.props;
|
|
1932
|
-
return this.prevProps && this.prevProps.routeInfo.pathname === routeInfo.pushedByRoute
|
|
1933
|
-
? this.prevProps.routeInfo
|
|
1934
|
-
: { pathname: routeInfo.pushedByRoute || '' };
|
|
1935
|
-
}
|
|
1936
227
|
componentDidMount() {
|
|
1937
|
-
this._isMounted = true;
|
|
1938
228
|
if (this.clearOutletTimeout) {
|
|
1939
229
|
/**
|
|
1940
230
|
* The clearOutlet integration with React Router is a bit hacky.
|
|
@@ -1965,186 +255,117 @@ class StackManager extends React.PureComponent {
|
|
|
1965
255
|
}
|
|
1966
256
|
}
|
|
1967
257
|
componentWillUnmount() {
|
|
1968
|
-
this._isMounted = false;
|
|
1969
|
-
// Cancel any in-flight transition rAFs
|
|
1970
|
-
for (const id of this.transitionRafIds) {
|
|
1971
|
-
cancelAnimationFrame(id);
|
|
1972
|
-
}
|
|
1973
|
-
this.transitionRafIds = [];
|
|
1974
|
-
// Disconnect any in-flight MutationObserver from waitForComponentsReady
|
|
1975
|
-
if (this.transitionObserver) {
|
|
1976
|
-
this.transitionObserver.disconnect();
|
|
1977
|
-
this.transitionObserver = undefined;
|
|
1978
|
-
}
|
|
1979
|
-
if (this.ionPageWaitTimeout) {
|
|
1980
|
-
clearTimeout(this.ionPageWaitTimeout);
|
|
1981
|
-
this.ionPageWaitTimeout = undefined;
|
|
1982
|
-
}
|
|
1983
|
-
if (this.outOfScopeUnmountTimeout) {
|
|
1984
|
-
clearTimeout(this.outOfScopeUnmountTimeout);
|
|
1985
|
-
this.outOfScopeUnmountTimeout = undefined;
|
|
1986
|
-
}
|
|
1987
|
-
this.waitingForIonPage = false;
|
|
1988
|
-
// Hide all views in this outlet before clearing.
|
|
1989
|
-
// This is critical for nested outlets - when the parent component unmounts,
|
|
1990
|
-
// the nested outlet's componentDidUpdate won't be called, so we must hide
|
|
1991
|
-
// the ion-page elements here to prevent them from remaining visible on top
|
|
1992
|
-
// of other content after navigation to a different route.
|
|
1993
|
-
const allViewsInOutlet = this.context.getViewItemsForOutlet(this.id);
|
|
1994
|
-
allViewsInOutlet.forEach((viewItem) => {
|
|
1995
|
-
hideIonPageElement(viewItem.ionPageElement);
|
|
1996
|
-
});
|
|
1997
258
|
this.clearOutletTimeout = this.context.clearOutlet(this.id);
|
|
1998
259
|
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Sets the transition between pages within this router outlet.
|
|
2001
|
-
* This function determines the entering and leaving views based on the
|
|
2002
|
-
* provided route information and triggers the appropriate animation.
|
|
2003
|
-
* It also handles scenarios like initial loads, back navigation, and
|
|
2004
|
-
* navigation to the same view with different parameters.
|
|
2005
|
-
*
|
|
2006
|
-
* @param routeInfo It contains info about the current route,
|
|
2007
|
-
* the previous route, and the action taken (e.g., push, replace).
|
|
2008
|
-
*
|
|
2009
|
-
* @returns A promise that resolves when the transition is complete.
|
|
2010
|
-
* If no transition is needed or if the router outlet isn't ready,
|
|
2011
|
-
* the Promise may resolve immediately.
|
|
2012
|
-
*/
|
|
2013
260
|
async handlePageTransition(routeInfo) {
|
|
2014
|
-
var _a;
|
|
2015
|
-
// Wait for router outlet to mount
|
|
261
|
+
var _a, _b;
|
|
2016
262
|
if (!this.routerOutletElement || !this.routerOutletElement.commit) {
|
|
263
|
+
/**
|
|
264
|
+
* The route outlet has not mounted yet. We need to wait for it to render
|
|
265
|
+
* before we can transition the page.
|
|
266
|
+
*
|
|
267
|
+
* Set a flag to indicate that we should transition the page after
|
|
268
|
+
* the component has updated.
|
|
269
|
+
*/
|
|
2017
270
|
this.pendingPageTransition = true;
|
|
2018
|
-
return;
|
|
2019
271
|
}
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
// Get parent path for nested outlets
|
|
2026
|
-
const parentPath = this.getParentPath();
|
|
2027
|
-
// Handle out-of-scope outlet (route outside mount path)
|
|
2028
|
-
if (this.handleOutOfScopeOutlet(routeInfo)) {
|
|
2029
|
-
return;
|
|
2030
|
-
}
|
|
2031
|
-
// Clear any pending out-of-scope unmount timeout
|
|
2032
|
-
if (this.outOfScopeUnmountTimeout) {
|
|
2033
|
-
clearTimeout(this.outOfScopeUnmountTimeout);
|
|
2034
|
-
this.outOfScopeUnmountTimeout = undefined;
|
|
2035
|
-
}
|
|
2036
|
-
// Handle nested outlet with relative routes but no valid parent path
|
|
2037
|
-
if (this.handleOutOfContextNestedOutlet(parentPath, leavingViewItem)) {
|
|
2038
|
-
return;
|
|
2039
|
-
}
|
|
2040
|
-
// Find the matching route element
|
|
2041
|
-
const enteringRoute = findRouteByRouteInfo((_a = this.ionRouterOutlet) === null || _a === void 0 ? void 0 : _a.props.children, routeInfo, parentPath);
|
|
2042
|
-
// Handle nested outlet with no matching route
|
|
2043
|
-
if (this.handleNoMatchingRoute(enteringRoute, enteringViewItem, leavingViewItem)) {
|
|
2044
|
-
return;
|
|
2045
|
-
}
|
|
2046
|
-
// Create or update the entering view item
|
|
2047
|
-
if (enteringViewItem && enteringRoute) {
|
|
2048
|
-
enteringViewItem.reactElement = enteringRoute;
|
|
2049
|
-
}
|
|
2050
|
-
else if (enteringRoute) {
|
|
2051
|
-
enteringViewItem = this.context.createViewItem(this.id, enteringRoute, routeInfo);
|
|
2052
|
-
this.context.addViewItem(enteringViewItem);
|
|
2053
|
-
}
|
|
2054
|
-
// Handle transition based on ion-page element availability
|
|
2055
|
-
// Check if the ionPageElement is still in the document.
|
|
2056
|
-
// If the view was previously unmounted (mount=false), the ViewLifeCycleManager
|
|
2057
|
-
// removes the React component from the tree, which removes the IonPage from the DOM.
|
|
2058
|
-
// The ionPageElement reference becomes stale and we need to wait for a new one.
|
|
2059
|
-
const ionPageIsInDocument = (enteringViewItem === null || enteringViewItem === void 0 ? void 0 : enteringViewItem.ionPageElement) && document.body.contains(enteringViewItem.ionPageElement);
|
|
2060
|
-
if (enteringViewItem && ionPageIsInDocument) {
|
|
2061
|
-
// Clear waiting state
|
|
2062
|
-
if (this.waitingForIonPage) {
|
|
2063
|
-
this.waitingForIonPage = false;
|
|
272
|
+
else {
|
|
273
|
+
let enteringViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id);
|
|
274
|
+
let leavingViewItem = this.context.findLeavingViewItemByRouteInfo(routeInfo, this.id);
|
|
275
|
+
if (!leavingViewItem && routeInfo.prevRouteLastPathname) {
|
|
276
|
+
leavingViewItem = this.context.findViewItemByPathname(routeInfo.prevRouteLastPathname, this.id);
|
|
2064
277
|
}
|
|
2065
|
-
if
|
|
2066
|
-
|
|
2067
|
-
|
|
278
|
+
// Check if leavingViewItem should be unmounted
|
|
279
|
+
if (leavingViewItem) {
|
|
280
|
+
if (routeInfo.routeAction === 'replace') {
|
|
281
|
+
leavingViewItem.mount = false;
|
|
282
|
+
}
|
|
283
|
+
else if (!(routeInfo.routeAction === 'push' && routeInfo.routeDirection === 'forward')) {
|
|
284
|
+
if (routeInfo.routeDirection !== 'none' && enteringViewItem !== leavingViewItem) {
|
|
285
|
+
leavingViewItem.mount = false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else if ((_a = routeInfo.routeOptions) === null || _a === void 0 ? void 0 : _a.unmount) {
|
|
289
|
+
leavingViewItem.mount = false;
|
|
290
|
+
}
|
|
2068
291
|
}
|
|
2069
|
-
this.
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
// Wait for ion-page to mount
|
|
2073
|
-
// This handles both: no ionPageElement, or stale ionPageElement (not in document)
|
|
2074
|
-
// Clear stale reference if the element is no longer in the document
|
|
2075
|
-
if (enteringViewItem.ionPageElement && !document.body.contains(enteringViewItem.ionPageElement)) {
|
|
2076
|
-
enteringViewItem.ionPageElement = undefined;
|
|
292
|
+
const enteringRoute = matchRoute((_b = this.ionRouterOutlet) === null || _b === void 0 ? void 0 : _b.props.children, routeInfo);
|
|
293
|
+
if (enteringViewItem) {
|
|
294
|
+
enteringViewItem.reactElement = enteringRoute;
|
|
2077
295
|
}
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
enteringViewItem
|
|
296
|
+
else if (enteringRoute) {
|
|
297
|
+
enteringViewItem = this.context.createViewItem(this.id, enteringRoute, routeInfo);
|
|
298
|
+
this.context.addViewItem(enteringViewItem);
|
|
2081
299
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
300
|
+
if (enteringViewItem && enteringViewItem.ionPageElement) {
|
|
301
|
+
/**
|
|
302
|
+
* If the entering view item is the same as the leaving view item,
|
|
303
|
+
* then we don't need to transition.
|
|
304
|
+
*/
|
|
305
|
+
if (enteringViewItem === leavingViewItem) {
|
|
306
|
+
/**
|
|
307
|
+
* If the entering view item is the same as the leaving view item,
|
|
308
|
+
* we are either transitioning using parameterized routes to the same view
|
|
309
|
+
* or a parent router outlet is re-rendering as a result of React props changing.
|
|
310
|
+
*
|
|
311
|
+
* If the route data does not match the current path, the parent router outlet
|
|
312
|
+
* is attempting to transition and we cancel the operation.
|
|
313
|
+
*/
|
|
314
|
+
if (enteringViewItem.routeData.match.url !== routeInfo.pathname) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* If there isn't a leaving view item, but the route info indicates
|
|
320
|
+
* that the user has routed from a previous path, then we need
|
|
321
|
+
* to find the leaving view item to transition between.
|
|
322
|
+
*/
|
|
323
|
+
if (!leavingViewItem && this.props.routeInfo.prevRouteLastPathname) {
|
|
324
|
+
leavingViewItem = this.context.findViewItemByPathname(this.props.routeInfo.prevRouteLastPathname, this.id);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* If the entering view is already visible and the leaving view is not, the transition does not need to occur.
|
|
328
|
+
*/
|
|
329
|
+
if (isViewVisible(enteringViewItem.ionPageElement) &&
|
|
330
|
+
leavingViewItem !== undefined &&
|
|
331
|
+
!isViewVisible(leavingViewItem.ionPageElement)) {
|
|
332
|
+
return;
|
|
2091
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* The view should only be transitioned in the following cases:
|
|
336
|
+
* 1. Performing a replace or pop action, such as a swipe to go back gesture
|
|
337
|
+
* to animation the leaving view off the screen.
|
|
338
|
+
*
|
|
339
|
+
* 2. Navigating between top-level router outlets, such as /page-1 to /page-2;
|
|
340
|
+
* or navigating within a nested outlet, such as /tabs/tab-1 to /tabs/tab-2.
|
|
341
|
+
*
|
|
342
|
+
* 3. The entering view is an ion-router-outlet containing a page
|
|
343
|
+
* matching the current route and that hasn't already transitioned in.
|
|
344
|
+
*
|
|
345
|
+
* This should only happen when navigating directly to a nested router outlet
|
|
346
|
+
* route or on an initial page load (i.e. refreshing). In cases when loading
|
|
347
|
+
* /tabs/tab-1, we need to transition the /tabs page element into the view.
|
|
348
|
+
*/
|
|
349
|
+
this.transitionPage(routeInfo, enteringViewItem, leavingViewItem);
|
|
350
|
+
}
|
|
351
|
+
else if (leavingViewItem && !enteringRoute && !enteringViewItem) {
|
|
352
|
+
// If we have a leavingView but no entering view/route, we are probably leaving to
|
|
353
|
+
// another outlet, so hide this leavingView. We do it in a timeout to give time for a
|
|
354
|
+
// transition to finish.
|
|
355
|
+
// setTimeout(() => {
|
|
356
|
+
if (leavingViewItem.ionPageElement) {
|
|
357
|
+
leavingViewItem.ionPageElement.classList.add('ion-page-hidden');
|
|
358
|
+
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
|
|
359
|
+
}
|
|
360
|
+
// }, 250);
|
|
2092
361
|
}
|
|
362
|
+
this.forceUpdate();
|
|
2093
363
|
}
|
|
2094
|
-
this.forceUpdate();
|
|
2095
364
|
}
|
|
2096
|
-
/**
|
|
2097
|
-
* Registers an `<IonPage>` DOM element with the `StackManager`.
|
|
2098
|
-
* This is called when `<IonPage>` has been mounted.
|
|
2099
|
-
*
|
|
2100
|
-
* @param page The element of the rendered `<IonPage>`.
|
|
2101
|
-
* @param routeInfo The route information that associates with `<IonPage>`.
|
|
2102
|
-
*/
|
|
2103
365
|
registerIonPage(page, routeInfo) {
|
|
2104
|
-
/**
|
|
2105
|
-
* DO NOT remove ion-page-invisible here.
|
|
2106
|
-
*
|
|
2107
|
-
* PageManager's ref callback adds ion-page-invisible synchronously to prevent flash.
|
|
2108
|
-
* At this point, the <IonPage> div exists but its CHILDREN (header, toolbar, menu-button)
|
|
2109
|
-
* have NOT rendered yet. If we remove ion-page-invisible now, the page becomes visible
|
|
2110
|
-
* with empty/incomplete content, causing a flicker (especially for ion-menu-button which
|
|
2111
|
-
* starts with menu-button-hidden class).
|
|
2112
|
-
*
|
|
2113
|
-
* Instead, let transitionPage handle visibility AFTER waiting for components to be ready.
|
|
2114
|
-
* This ensures the page only becomes visible when its content is fully rendered.
|
|
2115
|
-
*/
|
|
2116
|
-
this.waitingForIonPage = false;
|
|
2117
|
-
if (this.ionPageWaitTimeout) {
|
|
2118
|
-
clearTimeout(this.ionPageWaitTimeout);
|
|
2119
|
-
this.ionPageWaitTimeout = undefined;
|
|
2120
|
-
}
|
|
2121
|
-
this.pendingPageTransition = false;
|
|
2122
366
|
const foundView = this.context.findViewItemByRouteInfo(routeInfo, this.id);
|
|
2123
367
|
if (foundView) {
|
|
2124
368
|
const oldPageElement = foundView.ionPageElement;
|
|
2125
|
-
/**
|
|
2126
|
-
* FIX for issue #28878: Reject orphaned IonPage registrations.
|
|
2127
|
-
*
|
|
2128
|
-
* When a component conditionally renders different IonPages (e.g., list vs empty state)
|
|
2129
|
-
* using React keys, and state changes simultaneously with navigation, the new IonPage
|
|
2130
|
-
* tries to register for a route we're navigating away from. This creates a stale view.
|
|
2131
|
-
*
|
|
2132
|
-
* Only reject if both pageIds exist and differ, to allow nested outlet registrations.
|
|
2133
|
-
*/
|
|
2134
|
-
if (this.shouldRejectOrphanedPage(page, oldPageElement, routeInfo)) {
|
|
2135
|
-
this.hideAndRemoveOrphanedPage(page);
|
|
2136
|
-
return;
|
|
2137
|
-
}
|
|
2138
|
-
/**
|
|
2139
|
-
* Don't let a nested element (e.g., ion-router-outlet with ionPage prop)
|
|
2140
|
-
* override an existing IonPage registration when the existing element is
|
|
2141
|
-
* an ancestor of the new one. This ensures ionPageElement always points
|
|
2142
|
-
* to the outermost IonPage, which is needed to properly hide the entire
|
|
2143
|
-
* page during back navigation (not just the inner outlet).
|
|
2144
|
-
*/
|
|
2145
|
-
if (oldPageElement && oldPageElement !== page && oldPageElement.isConnected && oldPageElement.contains(page)) {
|
|
2146
|
-
return;
|
|
2147
|
-
}
|
|
2148
369
|
foundView.ionPageElement = page;
|
|
2149
370
|
foundView.ionRoute = true;
|
|
2150
371
|
/**
|
|
@@ -2158,32 +379,6 @@ class StackManager extends React.PureComponent {
|
|
|
2158
379
|
}
|
|
2159
380
|
this.handlePageTransition(routeInfo);
|
|
2160
381
|
}
|
|
2161
|
-
/**
|
|
2162
|
-
* Checks if a new IonPage should be rejected (component re-rendered while navigating away).
|
|
2163
|
-
*/
|
|
2164
|
-
shouldRejectOrphanedPage(newPage, oldPageElement, routeInfo) {
|
|
2165
|
-
if (!oldPageElement || oldPageElement === newPage) {
|
|
2166
|
-
return false;
|
|
2167
|
-
}
|
|
2168
|
-
const newPageId = newPage.getAttribute('data-pageid');
|
|
2169
|
-
const oldPageId = oldPageElement.getAttribute('data-pageid');
|
|
2170
|
-
if (!newPageId || !oldPageId || newPageId === oldPageId) {
|
|
2171
|
-
return false;
|
|
2172
|
-
}
|
|
2173
|
-
return this.props.routeInfo.pathname !== routeInfo.pathname;
|
|
2174
|
-
}
|
|
2175
|
-
hideAndRemoveOrphanedPage(page) {
|
|
2176
|
-
page.classList.add('ion-page-hidden');
|
|
2177
|
-
page.setAttribute('aria-hidden', 'true');
|
|
2178
|
-
setTimeout(() => {
|
|
2179
|
-
if (page.parentElement) {
|
|
2180
|
-
page.remove();
|
|
2181
|
-
}
|
|
2182
|
-
}, VIEW_UNMOUNT_DELAY_MS);
|
|
2183
|
-
}
|
|
2184
|
-
/**
|
|
2185
|
-
* Configures swipe-to-go-back gesture for the router outlet.
|
|
2186
|
-
*/
|
|
2187
382
|
async setupRouterOutlet(routerOutlet) {
|
|
2188
383
|
const canStart = () => {
|
|
2189
384
|
const config = getConfig();
|
|
@@ -2192,34 +387,40 @@ class StackManager extends React.PureComponent {
|
|
|
2192
387
|
return false;
|
|
2193
388
|
}
|
|
2194
389
|
const { routeInfo } = this.props;
|
|
2195
|
-
const
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
390
|
+
const propsToUse = this.prevProps && this.prevProps.routeInfo.pathname === routeInfo.pushedByRoute
|
|
391
|
+
? this.prevProps.routeInfo
|
|
392
|
+
: { pathname: routeInfo.pushedByRoute || '' };
|
|
393
|
+
const enteringViewItem = this.context.findViewItemByRouteInfo(propsToUse, this.id, false);
|
|
394
|
+
return (!!enteringViewItem &&
|
|
395
|
+
/**
|
|
396
|
+
* The root url '/' is treated as
|
|
397
|
+
* the first view item (but is never mounted),
|
|
398
|
+
* so we do not want to swipe back to the
|
|
399
|
+
* root url.
|
|
400
|
+
*/
|
|
401
|
+
enteringViewItem.mount &&
|
|
402
|
+
/**
|
|
403
|
+
* When on the first page (whatever view
|
|
404
|
+
* you land on after the root url) it
|
|
405
|
+
* is possible for findViewItemByRouteInfo to
|
|
406
|
+
* return the exact same view you are currently on.
|
|
407
|
+
* Make sure that we are not swiping back to the same
|
|
408
|
+
* instances of a view.
|
|
409
|
+
*/
|
|
410
|
+
enteringViewItem.routeData.match.path !== routeInfo.pathname);
|
|
2206
411
|
};
|
|
2207
412
|
const onStart = async () => {
|
|
2208
413
|
const { routeInfo } = this.props;
|
|
2209
|
-
const
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
enteringViewItem = this.context.findViewItemByRouteInfo(swipeBackRouteInfo, undefined, false);
|
|
2214
|
-
}
|
|
414
|
+
const propsToUse = this.prevProps && this.prevProps.routeInfo.pathname === routeInfo.pushedByRoute
|
|
415
|
+
? this.prevProps.routeInfo
|
|
416
|
+
: { pathname: routeInfo.pushedByRoute || '' };
|
|
417
|
+
const enteringViewItem = this.context.findViewItemByRouteInfo(propsToUse, this.id, false);
|
|
2215
418
|
const leavingViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id, false);
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
}
|
|
2222
|
-
// When the gesture starts, kick off a transition controlled via swipe gesture
|
|
419
|
+
/**
|
|
420
|
+
* When the gesture starts, kick off
|
|
421
|
+
* a transition that is controlled
|
|
422
|
+
* via a swipe gesture.
|
|
423
|
+
*/
|
|
2223
424
|
if (enteringViewItem && leavingViewItem) {
|
|
2224
425
|
await this.transitionPage(routeInfo, enteringViewItem, leavingViewItem, 'back', true);
|
|
2225
426
|
}
|
|
@@ -2227,23 +428,34 @@ class StackManager extends React.PureComponent {
|
|
|
2227
428
|
};
|
|
2228
429
|
const onEnd = (shouldContinue) => {
|
|
2229
430
|
if (shouldContinue) {
|
|
2230
|
-
// User finished the swipe gesture, so complete the back navigation
|
|
2231
431
|
this.skipTransition = true;
|
|
2232
432
|
this.context.goBack();
|
|
2233
433
|
}
|
|
2234
434
|
else {
|
|
2235
|
-
|
|
435
|
+
/**
|
|
436
|
+
* In the event that the swipe
|
|
437
|
+
* gesture was aborted, we should
|
|
438
|
+
* re-hide the page that was going to enter.
|
|
439
|
+
*/
|
|
2236
440
|
const { routeInfo } = this.props;
|
|
2237
|
-
const
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
enteringViewItem = this.context.findViewItemByRouteInfo(swipeBackRouteInfo, undefined, false);
|
|
2242
|
-
}
|
|
441
|
+
const propsToUse = this.prevProps && this.prevProps.routeInfo.pathname === routeInfo.pushedByRoute
|
|
442
|
+
? this.prevProps.routeInfo
|
|
443
|
+
: { pathname: routeInfo.pushedByRoute || '' };
|
|
444
|
+
const enteringViewItem = this.context.findViewItemByRouteInfo(propsToUse, this.id, false);
|
|
2243
445
|
const leavingViewItem = this.context.findViewItemByRouteInfo(routeInfo, this.id, false);
|
|
2244
|
-
|
|
446
|
+
/**
|
|
447
|
+
* Ionic React has a design defect where it
|
|
448
|
+
* a) Unmounts the leaving view item when using parameterized routes
|
|
449
|
+
* b) Considers the current view to be the entering view when using
|
|
450
|
+
* parameterized routes
|
|
451
|
+
*
|
|
452
|
+
* As a result, we should not hide the view item here
|
|
453
|
+
* as it will cause the current view to be hidden.
|
|
454
|
+
*/
|
|
2245
455
|
if (enteringViewItem !== leavingViewItem && (enteringViewItem === null || enteringViewItem === void 0 ? void 0 : enteringViewItem.ionPageElement) !== undefined) {
|
|
2246
|
-
|
|
456
|
+
const { ionPageElement } = enteringViewItem;
|
|
457
|
+
ionPageElement.setAttribute('aria-hidden', 'true');
|
|
458
|
+
ionPageElement.classList.add('ion-page-hidden');
|
|
2247
459
|
}
|
|
2248
460
|
}
|
|
2249
461
|
};
|
|
@@ -2253,23 +465,7 @@ class StackManager extends React.PureComponent {
|
|
|
2253
465
|
onEnd,
|
|
2254
466
|
};
|
|
2255
467
|
}
|
|
2256
|
-
|
|
2257
|
-
* Animates the transition between the entering and leaving pages within the
|
|
2258
|
-
* router outlet.
|
|
2259
|
-
*
|
|
2260
|
-
* @param routeInfo Info about the current route.
|
|
2261
|
-
* @param enteringViewItem The view item that is entering.
|
|
2262
|
-
* @param leavingViewItem The view item that is leaving.
|
|
2263
|
-
* @param direction The direction of the transition.
|
|
2264
|
-
* @param progressAnimation Indicates if the transition is part of a
|
|
2265
|
-
* gesture controlled animation (e.g., swipe to go back).
|
|
2266
|
-
* Defaults to `false`.
|
|
2267
|
-
* @param skipAnimation When true, forces `duration: 0` so the page
|
|
2268
|
-
* swap is instant (no visible animation). Used for ionPage outlets
|
|
2269
|
-
* and back navigations that unmount the leaving view to prevent
|
|
2270
|
-
* overlapping content during the transition. Defaults to `false`.
|
|
2271
|
-
*/
|
|
2272
|
-
async transitionPage(routeInfo, enteringViewItem, leavingViewItem, direction, progressAnimation = false, skipAnimation = false) {
|
|
468
|
+
async transitionPage(routeInfo, enteringViewItem, leavingViewItem, direction, progressAnimation = false) {
|
|
2273
469
|
const runCommit = async (enteringEl, leavingEl) => {
|
|
2274
470
|
const skipTransition = this.skipTransition;
|
|
2275
471
|
/**
|
|
@@ -2297,43 +493,24 @@ class StackManager extends React.PureComponent {
|
|
|
2297
493
|
}
|
|
2298
494
|
else {
|
|
2299
495
|
enteringEl.classList.add('ion-page');
|
|
2300
|
-
|
|
2301
|
-
* Only add ion-page-invisible if the element is not already visible.
|
|
2302
|
-
* During tab switches, the container page (e.g., TabContext wrapper) is
|
|
2303
|
-
* already visible and should remain so. Adding ion-page-invisible would
|
|
2304
|
-
* cause a flash where the visible page briefly becomes invisible.
|
|
2305
|
-
*/
|
|
2306
|
-
if (!isViewVisible(enteringEl)) {
|
|
2307
|
-
enteringEl.classList.add('ion-page-invisible');
|
|
2308
|
-
}
|
|
496
|
+
enteringEl.classList.add('ion-page-invisible');
|
|
2309
497
|
}
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
const commitPromise = routerOutlet.commit(enteringEl, leavingEl, {
|
|
2313
|
-
duration: commitDuration,
|
|
498
|
+
await routerOutlet.commit(enteringEl, leavingEl, {
|
|
499
|
+
duration: skipTransition || directionToUse === undefined ? 0 : undefined,
|
|
2314
500
|
direction: directionToUse,
|
|
2315
501
|
showGoBack: !!routeInfo.pushedByRoute,
|
|
2316
502
|
progressAnimation,
|
|
2317
503
|
animationBuilder: routeInfo.routeAnimation,
|
|
2318
504
|
});
|
|
2319
|
-
const timeoutMs = 5000;
|
|
2320
|
-
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve('timeout'), timeoutMs));
|
|
2321
|
-
const result = await Promise.race([commitPromise.then(() => 'done'), timeoutPromise]);
|
|
2322
|
-
if (result === 'timeout') {
|
|
2323
|
-
// Force entering page visible even though commit hung
|
|
2324
|
-
enteringEl.classList.remove('ion-page-invisible');
|
|
2325
|
-
}
|
|
2326
|
-
if (!progressAnimation) {
|
|
2327
|
-
enteringEl.classList.remove('ion-page-invisible');
|
|
2328
|
-
}
|
|
2329
505
|
};
|
|
2330
506
|
const routerOutlet = this.routerOutletElement;
|
|
2331
507
|
const routeInfoFallbackDirection = routeInfo.routeDirection === 'none' || routeInfo.routeDirection === 'root' ? undefined : routeInfo.routeDirection;
|
|
2332
508
|
const directionToUse = direction !== null && direction !== void 0 ? direction : routeInfoFallbackDirection;
|
|
2333
509
|
if (enteringViewItem && enteringViewItem.ionPageElement && this.routerOutletElement) {
|
|
2334
510
|
if (leavingViewItem && leavingViewItem.ionPageElement && enteringViewItem === leavingViewItem) {
|
|
2335
|
-
//
|
|
2336
|
-
|
|
511
|
+
// If a page is transitioning to another version of itself
|
|
512
|
+
// we clone it so we can have an animation to show
|
|
513
|
+
const match = matchComponent(leavingViewItem.reactElement, routeInfo.pathname, true);
|
|
2337
514
|
if (match) {
|
|
2338
515
|
const newLeavingElement = clonePageElement(leavingViewItem.ionPageElement.outerHTML);
|
|
2339
516
|
if (newLeavingElement) {
|
|
@@ -2343,104 +520,14 @@ class StackManager extends React.PureComponent {
|
|
|
2343
520
|
}
|
|
2344
521
|
}
|
|
2345
522
|
else {
|
|
2346
|
-
// Route no longer matches (e.g., /user/1 → /settings)
|
|
2347
523
|
await runCommit(enteringViewItem.ionPageElement, undefined);
|
|
2348
524
|
}
|
|
2349
525
|
}
|
|
2350
526
|
else {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
if (isNonAnimatedTransition && leavingEl) {
|
|
2356
|
-
/**
|
|
2357
|
-
* Skip commit() for non-animated transitions (like tab switches).
|
|
2358
|
-
* commit() runs animation logic that can cause intermediate paints
|
|
2359
|
-
* even with duration: 0. Instead, swap visibility synchronously.
|
|
2360
|
-
*
|
|
2361
|
-
* Synchronous DOM class changes are batched into a single browser
|
|
2362
|
-
* paint, so there's no gap frame where neither page is visible and
|
|
2363
|
-
* no overlap frame where both pages are visible.
|
|
2364
|
-
*/
|
|
2365
|
-
const enteringEl = enteringViewItem.ionPageElement;
|
|
2366
|
-
// Ensure entering element has proper base classes
|
|
2367
|
-
enteringEl.classList.add('ion-page');
|
|
2368
|
-
// Clear ALL hidden state from entering element. showIonPageElement
|
|
2369
|
-
// removes visibility:hidden (from applySkipAnimationIfNeeded),
|
|
2370
|
-
// ion-page-hidden, and aria-hidden in one call.
|
|
2371
|
-
showIonPageElement(enteringEl);
|
|
2372
|
-
// Handle can-go-back class since we're skipping commit() which normally sets this
|
|
2373
|
-
if (routeInfo.pushedByRoute) {
|
|
2374
|
-
enteringEl.classList.add('can-go-back');
|
|
2375
|
-
}
|
|
2376
|
-
else {
|
|
2377
|
-
enteringEl.classList.remove('can-go-back');
|
|
2378
|
-
}
|
|
2379
|
-
/**
|
|
2380
|
-
* Wait for components to be ready. Menu buttons start hidden (menu-button-hidden)
|
|
2381
|
-
* and become visible after componentDidLoad. Wait for hydration and visibility.
|
|
2382
|
-
*/
|
|
2383
|
-
const waitForComponentsReady = () => {
|
|
2384
|
-
return new Promise((resolve) => {
|
|
2385
|
-
const checkReady = () => {
|
|
2386
|
-
const ionicComponents = enteringEl.querySelectorAll('ion-header, ion-toolbar, ion-buttons, ion-menu-button, ion-title, ion-content');
|
|
2387
|
-
const allHydrated = Array.from(ionicComponents).every((el) => el.classList.contains('hydrated'));
|
|
2388
|
-
const menuButtons = enteringEl.querySelectorAll('ion-menu-button');
|
|
2389
|
-
const menuButtonsReady = Array.from(menuButtons).every((el) => !el.classList.contains('menu-button-hidden'));
|
|
2390
|
-
return allHydrated && menuButtonsReady;
|
|
2391
|
-
};
|
|
2392
|
-
if (checkReady()) {
|
|
2393
|
-
resolve();
|
|
2394
|
-
return;
|
|
2395
|
-
}
|
|
2396
|
-
let resolved = false;
|
|
2397
|
-
const observer = new MutationObserver(() => {
|
|
2398
|
-
if (!resolved && checkReady()) {
|
|
2399
|
-
resolved = true;
|
|
2400
|
-
observer.disconnect();
|
|
2401
|
-
if (this.transitionObserver === observer) {
|
|
2402
|
-
this.transitionObserver = undefined;
|
|
2403
|
-
}
|
|
2404
|
-
resolve();
|
|
2405
|
-
}
|
|
2406
|
-
});
|
|
2407
|
-
// Disconnect any previous observer before tracking the new one
|
|
2408
|
-
if (this.transitionObserver) {
|
|
2409
|
-
this.transitionObserver.disconnect();
|
|
2410
|
-
}
|
|
2411
|
-
this.transitionObserver = observer;
|
|
2412
|
-
observer.observe(enteringEl, {
|
|
2413
|
-
subtree: true,
|
|
2414
|
-
attributes: true,
|
|
2415
|
-
attributeFilter: ['class'],
|
|
2416
|
-
});
|
|
2417
|
-
setTimeout(() => {
|
|
2418
|
-
if (!resolved) {
|
|
2419
|
-
resolved = true;
|
|
2420
|
-
observer.disconnect();
|
|
2421
|
-
if (this.transitionObserver === observer) {
|
|
2422
|
-
this.transitionObserver = undefined;
|
|
2423
|
-
}
|
|
2424
|
-
resolve();
|
|
2425
|
-
}
|
|
2426
|
-
}, 100);
|
|
2427
|
-
});
|
|
2428
|
-
};
|
|
2429
|
-
await waitForComponentsReady();
|
|
2430
|
-
// Bail out if the component unmounted during waitForComponentsReady
|
|
2431
|
-
if (!this._isMounted)
|
|
2432
|
-
return;
|
|
2433
|
-
// Swap visibility synchronously - show entering, hide leaving
|
|
2434
|
-
enteringEl.classList.remove('ion-page-invisible');
|
|
2435
|
-
leavingEl.classList.add('ion-page-hidden');
|
|
2436
|
-
leavingEl.setAttribute('aria-hidden', 'true');
|
|
2437
|
-
}
|
|
2438
|
-
else {
|
|
2439
|
-
await runCommit(enteringViewItem.ionPageElement, leavingEl);
|
|
2440
|
-
if (leavingEl && !progressAnimation) {
|
|
2441
|
-
leavingEl.classList.add('ion-page-hidden');
|
|
2442
|
-
leavingEl.setAttribute('aria-hidden', 'true');
|
|
2443
|
-
}
|
|
527
|
+
await runCommit(enteringViewItem.ionPageElement, leavingViewItem === null || leavingViewItem === void 0 ? void 0 : leavingViewItem.ionPageElement);
|
|
528
|
+
if (leavingViewItem && leavingViewItem.ionPageElement && !progressAnimation) {
|
|
529
|
+
leavingViewItem.ionPageElement.classList.add('ion-page-hidden');
|
|
530
|
+
leavingViewItem.ionPageElement.setAttribute('aria-hidden', 'true');
|
|
2444
531
|
}
|
|
2445
532
|
}
|
|
2446
533
|
}
|
|
@@ -2448,494 +535,193 @@ class StackManager extends React.PureComponent {
|
|
|
2448
535
|
render() {
|
|
2449
536
|
const { children } = this.props;
|
|
2450
537
|
const ionRouterOutlet = React.Children.only(children);
|
|
2451
|
-
// Store reference for use in getParentPath() and handlePageTransition()
|
|
2452
538
|
this.ionRouterOutlet = ionRouterOutlet;
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
return (React.createElement(StackContext.Provider, { value: this.stackContextValue }, React.cloneElement(ionRouterOutlet, {
|
|
2472
|
-
ref: (node) => {
|
|
2473
|
-
if (ionRouterOutlet.props.setRef) {
|
|
2474
|
-
// Needed to handle external refs from devs.
|
|
2475
|
-
ionRouterOutlet.props.setRef(node);
|
|
2476
|
-
}
|
|
2477
|
-
if (ionRouterOutlet.props.forwardedRef) {
|
|
2478
|
-
// Needed to handle external refs from devs.
|
|
2479
|
-
ionRouterOutlet.props.forwardedRef.current = node;
|
|
2480
|
-
}
|
|
2481
|
-
this.routerOutletElement = node;
|
|
2482
|
-
const { ref } = ionRouterOutlet;
|
|
2483
|
-
// Check for legacy refs.
|
|
2484
|
-
if (typeof ref === 'function') {
|
|
2485
|
-
ref(node);
|
|
2486
|
-
}
|
|
2487
|
-
},
|
|
2488
|
-
}, components)));
|
|
2489
|
-
}));
|
|
539
|
+
const components = this.context.getChildrenToRender(this.id, this.ionRouterOutlet, this.props.routeInfo, () => {
|
|
540
|
+
this.forceUpdate();
|
|
541
|
+
});
|
|
542
|
+
return (React.createElement(StackContext.Provider, { value: this.stackContextValue }, React.cloneElement(ionRouterOutlet, {
|
|
543
|
+
ref: (node) => {
|
|
544
|
+
if (ionRouterOutlet.props.setRef) {
|
|
545
|
+
ionRouterOutlet.props.setRef(node);
|
|
546
|
+
}
|
|
547
|
+
if (ionRouterOutlet.props.forwardedRef) {
|
|
548
|
+
ionRouterOutlet.props.forwardedRef.current = node;
|
|
549
|
+
}
|
|
550
|
+
this.routerOutletElement = node;
|
|
551
|
+
const { ref } = ionRouterOutlet;
|
|
552
|
+
if (typeof ref === 'function') {
|
|
553
|
+
ref(node);
|
|
554
|
+
}
|
|
555
|
+
},
|
|
556
|
+
}, components)));
|
|
2490
557
|
}
|
|
2491
558
|
static get contextType() {
|
|
2492
559
|
return RouteManagerContext;
|
|
2493
560
|
}
|
|
2494
561
|
}
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
* @param routeChildren The flat array of Route/IonRoute elements from the outlet.
|
|
2505
|
-
* @param basename The resolved parent path (without trailing slash or `/*`) used to relativize absolute paths.
|
|
2506
|
-
*/
|
|
2507
|
-
function routeElementsToRouteObjects(routeChildren, basename) {
|
|
2508
|
-
return routeChildren
|
|
2509
|
-
.filter((child) => child.props.path != null || child.props.index)
|
|
2510
|
-
.map((child) => {
|
|
2511
|
-
const handle = { _element: child };
|
|
2512
|
-
let path = child.props.path;
|
|
2513
|
-
// Relativize absolute paths by stripping the basename prefix
|
|
2514
|
-
if (path && path.startsWith('/') && basename) {
|
|
2515
|
-
if (path === basename) {
|
|
2516
|
-
path = '';
|
|
2517
|
-
}
|
|
2518
|
-
else if (path.startsWith(basename + '/')) {
|
|
2519
|
-
path = path.slice(basename.length + 1);
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
if (child.props.index) {
|
|
2523
|
-
return {
|
|
2524
|
-
index: true,
|
|
2525
|
-
handle,
|
|
2526
|
-
caseSensitive: child.props.caseSensitive || undefined,
|
|
2527
|
-
};
|
|
562
|
+
function matchRoute(node, routeInfo) {
|
|
563
|
+
let matchedNode;
|
|
564
|
+
React.Children.forEach(node, (child) => {
|
|
565
|
+
const match = matchPath({
|
|
566
|
+
pathname: routeInfo.pathname,
|
|
567
|
+
componentProps: child.props,
|
|
568
|
+
});
|
|
569
|
+
if (match) {
|
|
570
|
+
matchedNode = child;
|
|
2528
571
|
}
|
|
2529
|
-
return {
|
|
2530
|
-
path,
|
|
2531
|
-
handle,
|
|
2532
|
-
caseSensitive: child.props.caseSensitive || undefined,
|
|
2533
|
-
};
|
|
2534
572
|
});
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
* Finds the `<Route />` node matching the current route info.
|
|
2538
|
-
* If no `<Route />` can be matched, a fallback node is returned.
|
|
2539
|
-
* Routes are prioritized by specificity (most specific first).
|
|
2540
|
-
*
|
|
2541
|
-
* @param node The root node to search for `<Route />` nodes.
|
|
2542
|
-
* @param routeInfo The route information to match against.
|
|
2543
|
-
* @param parentPath The parent path that was matched by the parent outlet (for nested routing)
|
|
2544
|
-
*/
|
|
2545
|
-
function findRouteByRouteInfo(node, routeInfo, parentPath) {
|
|
2546
|
-
var _a, _b, _c;
|
|
2547
|
-
let matchedNode;
|
|
2548
|
-
let fallbackNode;
|
|
2549
|
-
// `<Route />` nodes are rendered inside of a <Routes /> node
|
|
2550
|
-
const routesChildren = (_a = getRoutesChildren(node)) !== null && _a !== void 0 ? _a : node;
|
|
2551
|
-
// Collect all route children
|
|
2552
|
-
const routeChildren = React.Children.toArray(routesChildren).filter((child) => React.isValidElement(child) && (child.type === Route || child.type === IonRoute));
|
|
2553
|
-
// Delegate route matching to RR6's matchRoutes(), which handles specificity ranking internally.
|
|
2554
|
-
const basename = parentPath ? stripTrailingSlash(parentPath.replace('/*', '')) : undefined;
|
|
2555
|
-
const routeObjects = routeElementsToRouteObjects(routeChildren, basename);
|
|
2556
|
-
const matches = matchRoutes(routeObjects, { pathname: routeInfo.pathname }, basename);
|
|
2557
|
-
if (matches && matches.length > 0) {
|
|
2558
|
-
const bestMatch = matches[matches.length - 1];
|
|
2559
|
-
matchedNode = (_c = (_b = bestMatch.route.handle) === null || _b === void 0 ? void 0 : _b._element) !== null && _c !== void 0 ? _c : undefined;
|
|
573
|
+
if (matchedNode) {
|
|
574
|
+
return matchedNode;
|
|
2560
575
|
}
|
|
2561
|
-
//
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
if (
|
|
2565
|
-
|
|
2566
|
-
}
|
|
2567
|
-
else {
|
|
2568
|
-
const absolutePathRoutes = routeChildren.filter((r) => r.props.path && r.props.path.startsWith('/'));
|
|
2569
|
-
if (absolutePathRoutes.length > 0) {
|
|
2570
|
-
const absolutePaths = absolutePathRoutes.map((r) => r.props.path);
|
|
2571
|
-
const commonPrefix = computeCommonPrefix(absolutePaths);
|
|
2572
|
-
if (commonPrefix && commonPrefix !== '/') {
|
|
2573
|
-
pathnameInScope = routeInfo.pathname.startsWith(commonPrefix);
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
}
|
|
2577
|
-
if (pathnameInScope) {
|
|
2578
|
-
for (const child of routeChildren) {
|
|
2579
|
-
if (!child.props.path) {
|
|
2580
|
-
fallbackNode = child;
|
|
2581
|
-
break;
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
576
|
+
// If we haven't found a node
|
|
577
|
+
// try to find one that doesn't have a path or from prop, that will be our not found route
|
|
578
|
+
React.Children.forEach(node, (child) => {
|
|
579
|
+
if (!(child.props.path || child.props.from)) {
|
|
580
|
+
matchedNode = child;
|
|
2584
581
|
}
|
|
2585
|
-
}
|
|
2586
|
-
return matchedNode
|
|
582
|
+
});
|
|
583
|
+
return matchedNode;
|
|
2587
584
|
}
|
|
2588
|
-
function matchComponent(node, pathname, forceExact
|
|
2589
|
-
var _a;
|
|
2590
|
-
const routePath = (_a = node === null || node === void 0 ? void 0 : node.props) === null || _a === void 0 ? void 0 : _a.path;
|
|
2591
|
-
let pathnameToMatch;
|
|
2592
|
-
if (parentPath && routePath && !routePath.startsWith('/')) {
|
|
2593
|
-
// When parent path is known, compute exact relative pathname
|
|
2594
|
-
const relative = pathname.startsWith(parentPath)
|
|
2595
|
-
? pathname.slice(parentPath.length).replace(/^\//, '')
|
|
2596
|
-
: pathname;
|
|
2597
|
-
pathnameToMatch = relative;
|
|
2598
|
-
}
|
|
2599
|
-
else {
|
|
2600
|
-
pathnameToMatch = derivePathnameToMatch(pathname, routePath);
|
|
2601
|
-
}
|
|
585
|
+
function matchComponent(node, pathname, forceExact) {
|
|
2602
586
|
return matchPath({
|
|
2603
|
-
pathname
|
|
2604
|
-
componentProps: Object.assign(Object.assign({}, node.props), {
|
|
587
|
+
pathname,
|
|
588
|
+
componentProps: Object.assign(Object.assign({}, node.props), { exact: forceExact }),
|
|
2605
589
|
});
|
|
2606
590
|
}
|
|
2607
591
|
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
walker = history.findLastLocation(walker);
|
|
2643
|
-
}
|
|
2644
|
-
return false;
|
|
2645
|
-
};
|
|
2646
|
-
const areParamsEqual = (a, b) => {
|
|
2647
|
-
const paramsA = a || {};
|
|
2648
|
-
const paramsB = b || {};
|
|
2649
|
-
const keysA = Object.keys(paramsA);
|
|
2650
|
-
const keysB = Object.keys(paramsB);
|
|
2651
|
-
if (keysA.length !== keysB.length) {
|
|
2652
|
-
return false;
|
|
592
|
+
class IonRouterInner extends React.PureComponent {
|
|
593
|
+
constructor(props) {
|
|
594
|
+
super(props);
|
|
595
|
+
this.exitViewFromOtherOutletHandlers = [];
|
|
596
|
+
this.locationHistory = new LocationHistory();
|
|
597
|
+
this.viewStack = new ReactRouterViewStack();
|
|
598
|
+
this.routeMangerContextState = {
|
|
599
|
+
canGoBack: () => this.locationHistory.canGoBack(),
|
|
600
|
+
clearOutlet: this.viewStack.clear,
|
|
601
|
+
findViewItemByPathname: this.viewStack.findViewItemByPathname,
|
|
602
|
+
getChildrenToRender: this.viewStack.getChildrenToRender,
|
|
603
|
+
goBack: () => this.handleNavigateBack(),
|
|
604
|
+
createViewItem: this.viewStack.createViewItem,
|
|
605
|
+
findViewItemByRouteInfo: this.viewStack.findViewItemByRouteInfo,
|
|
606
|
+
findLeavingViewItemByRouteInfo: this.viewStack.findLeavingViewItemByRouteInfo,
|
|
607
|
+
addViewItem: this.viewStack.add,
|
|
608
|
+
unMountViewItem: this.viewStack.remove,
|
|
609
|
+
};
|
|
610
|
+
const routeInfo = {
|
|
611
|
+
id: generateId('routeInfo'),
|
|
612
|
+
pathname: this.props.location.pathname,
|
|
613
|
+
search: this.props.location.search,
|
|
614
|
+
};
|
|
615
|
+
this.locationHistory.add(routeInfo);
|
|
616
|
+
this.handleChangeTab = this.handleChangeTab.bind(this);
|
|
617
|
+
this.handleResetTab = this.handleResetTab.bind(this);
|
|
618
|
+
this.handleNativeBack = this.handleNativeBack.bind(this);
|
|
619
|
+
this.handleNavigate = this.handleNavigate.bind(this);
|
|
620
|
+
this.handleNavigateBack = this.handleNavigateBack.bind(this);
|
|
621
|
+
this.props.registerHistoryListener(this.handleHistoryChange.bind(this));
|
|
622
|
+
this.handleSetCurrentTab = this.handleSetCurrentTab.bind(this);
|
|
623
|
+
this.state = {
|
|
624
|
+
routeInfo,
|
|
625
|
+
};
|
|
2653
626
|
}
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
const valueB = paramsB[key];
|
|
2657
|
-
if (Array.isArray(valueA) && Array.isArray(valueB)) {
|
|
2658
|
-
if (valueA.length !== valueB.length) {
|
|
2659
|
-
return false;
|
|
2660
|
-
}
|
|
2661
|
-
return valueA.every((entry, idx) => entry === valueB[idx]);
|
|
2662
|
-
}
|
|
2663
|
-
return valueA === valueB;
|
|
2664
|
-
});
|
|
2665
|
-
};
|
|
2666
|
-
const IonRouter = ({ children, registerHistoryListener }) => {
|
|
2667
|
-
const location = useLocation();
|
|
2668
|
-
const navigate = useNavigate();
|
|
2669
|
-
const didMountRef = useRef(false);
|
|
2670
|
-
const locationHistory = useRef(new LocationHistory());
|
|
2671
|
-
const currentTab = useRef(undefined);
|
|
2672
|
-
const viewStack = useRef(new ReactRouterViewStack());
|
|
2673
|
-
const incomingRouteParams = useRef(null);
|
|
2674
|
-
/**
|
|
2675
|
-
* Tracks location keys that the user navigated away from via browser back.
|
|
2676
|
-
* When a POP event's destination key matches the top of this stack, it's a
|
|
2677
|
-
* browser forward navigation. Uses React Router's unique location.key
|
|
2678
|
-
* instead of URLs to correctly handle duplicate URLs in history (e.g.,
|
|
2679
|
-
* navigating to /details, then /settings, then /details via routerLink,
|
|
2680
|
-
* then pressing back).
|
|
2681
|
-
* Cleared on PUSH (new navigation invalidates forward history).
|
|
2682
|
-
*/
|
|
2683
|
-
const forwardStack = useRef([]);
|
|
2684
|
-
/**
|
|
2685
|
-
* Tracks the current location key so we can push it onto the forward stack
|
|
2686
|
-
* when navigating back. Updated after each history change.
|
|
2687
|
-
*/
|
|
2688
|
-
const currentLocationKeyRef = useRef(location.key);
|
|
2689
|
-
const [routeInfo, setRouteInfo] = useState({
|
|
2690
|
-
id: generateId('routeInfo'),
|
|
2691
|
-
pathname: location.pathname,
|
|
2692
|
-
search: location.search,
|
|
2693
|
-
params: {},
|
|
2694
|
-
});
|
|
2695
|
-
useEffect(() => {
|
|
2696
|
-
if (didMountRef.current) {
|
|
627
|
+
handleChangeTab(tab, path, routeOptions) {
|
|
628
|
+
if (!path) {
|
|
2697
629
|
return;
|
|
2698
630
|
}
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
if (currentTab.current) {
|
|
2707
|
-
const ri = Object.assign({}, locationHistory.current.current());
|
|
2708
|
-
if (ri.tab !== currentTab.current) {
|
|
2709
|
-
ri.tab = currentTab.current;
|
|
2710
|
-
locationHistory.current.update(ri);
|
|
631
|
+
const routeInfo = this.locationHistory.getCurrentRouteInfoForTab(tab);
|
|
632
|
+
const [pathname, search] = path.split('?');
|
|
633
|
+
if (routeInfo) {
|
|
634
|
+
this.incomingRouteParams = Object.assign(Object.assign({}, routeInfo), { routeAction: 'push', routeDirection: 'none' });
|
|
635
|
+
if (routeInfo.pathname === pathname) {
|
|
636
|
+
this.incomingRouteParams.routeOptions = routeOptions;
|
|
637
|
+
this.props.history.push(routeInfo.pathname + (routeInfo.search || ''));
|
|
2711
638
|
}
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
// The view stack's match may contain params (e.g., :id) not present in the initial routeInfo.
|
|
2718
|
-
useEffect(() => {
|
|
2719
|
-
var _a;
|
|
2720
|
-
const activeView = viewStack.current.findViewItemByRouteInfo(routeInfo, undefined, true);
|
|
2721
|
-
const matchedParams = (_a = activeView === null || activeView === void 0 ? void 0 : activeView.routeData.match) === null || _a === void 0 ? void 0 : _a.params;
|
|
2722
|
-
if (matchedParams) {
|
|
2723
|
-
const paramsCopy = filterUndefinedParams(Object.assign({}, matchedParams));
|
|
2724
|
-
if (areParamsEqual(routeInfo.params, paramsCopy)) {
|
|
2725
|
-
return;
|
|
639
|
+
else {
|
|
640
|
+
this.incomingRouteParams.pathname = pathname;
|
|
641
|
+
this.incomingRouteParams.search = search ? '?' + search : undefined;
|
|
642
|
+
this.incomingRouteParams.routeOptions = routeOptions;
|
|
643
|
+
this.props.history.push(pathname + (search ? '?' + search : ''));
|
|
2726
644
|
}
|
|
2727
|
-
const updatedRouteInfo = Object.assign(Object.assign({}, routeInfo), { params: paramsCopy });
|
|
2728
|
-
locationHistory.current.update(updatedRouteInfo);
|
|
2729
|
-
setRouteInfo(updatedRouteInfo);
|
|
2730
645
|
}
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
*
|
|
2738
|
-
* @param location The current location object from the history.
|
|
2739
|
-
* @param action The action that triggered the history change.
|
|
2740
|
-
*/
|
|
2741
|
-
const handleHistoryChange = (location, action) => {
|
|
2742
|
-
var _a, _b, _c, _d, _e;
|
|
646
|
+
else {
|
|
647
|
+
this.handleNavigate(pathname, 'push', 'none', undefined, routeOptions, tab);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
handleHistoryChange(location, action) {
|
|
651
|
+
var _a, _b, _c;
|
|
2743
652
|
let leavingLocationInfo;
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
*/
|
|
2748
|
-
if (incomingRouteParams.current) {
|
|
2749
|
-
/**
|
|
2750
|
-
* The current history entry is overwritten, so the previous entry
|
|
2751
|
-
* is the one we are leaving.
|
|
2752
|
-
*/
|
|
2753
|
-
if (((_a = incomingRouteParams.current) === null || _a === void 0 ? void 0 : _a.routeAction) === 'replace') {
|
|
2754
|
-
leavingLocationInfo = locationHistory.current.previous();
|
|
653
|
+
if (this.incomingRouteParams) {
|
|
654
|
+
if (this.incomingRouteParams.routeAction === 'replace') {
|
|
655
|
+
leavingLocationInfo = this.locationHistory.previous();
|
|
2755
656
|
}
|
|
2756
657
|
else {
|
|
2757
|
-
|
|
2758
|
-
leavingLocationInfo = locationHistory.current.current();
|
|
658
|
+
leavingLocationInfo = this.locationHistory.current();
|
|
2759
659
|
}
|
|
2760
660
|
}
|
|
2761
661
|
else {
|
|
2762
|
-
|
|
2763
|
-
* An external navigation was triggered
|
|
2764
|
-
* e.g., browser back/forward button or direct link
|
|
2765
|
-
*
|
|
2766
|
-
* The leaving location is the current route.
|
|
2767
|
-
*/
|
|
2768
|
-
leavingLocationInfo = locationHistory.current.current();
|
|
662
|
+
leavingLocationInfo = this.locationHistory.current();
|
|
2769
663
|
}
|
|
2770
664
|
const leavingUrl = leavingLocationInfo.pathname + leavingLocationInfo.search;
|
|
2771
|
-
if (leavingUrl !== location.pathname
|
|
2772
|
-
if (!incomingRouteParams
|
|
2773
|
-
// Use history-based tab detection instead of URL-pattern heuristics,
|
|
2774
|
-
// so tab routes work with any URL structure (not just paths containing "/tabs").
|
|
2775
|
-
// Fall back to currentTab.current only when the destination is within the
|
|
2776
|
-
// current tab's path hierarchy (prevents non-tab routes from inheriting a tab).
|
|
2777
|
-
let tabToUse = locationHistory.current.findTabForPathname(location.pathname);
|
|
2778
|
-
if (!tabToUse && currentTab.current) {
|
|
2779
|
-
const tabFirstRoute = locationHistory.current.getFirstRouteInfoForTab(currentTab.current);
|
|
2780
|
-
const tabRootPath = tabFirstRoute === null || tabFirstRoute === void 0 ? void 0 : tabFirstRoute.pathname;
|
|
2781
|
-
if (tabRootPath && (location.pathname === tabRootPath || location.pathname.startsWith(tabRootPath + '/'))) {
|
|
2782
|
-
tabToUse = currentTab.current;
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
/**
|
|
2786
|
-
* A `REPLACE` action can be triggered by React Router's
|
|
2787
|
-
* `<Navigate />` component.
|
|
2788
|
-
*/
|
|
665
|
+
if (leavingUrl !== location.pathname) {
|
|
666
|
+
if (!this.incomingRouteParams) {
|
|
2789
667
|
if (action === 'REPLACE') {
|
|
2790
|
-
incomingRouteParams
|
|
668
|
+
this.incomingRouteParams = {
|
|
2791
669
|
routeAction: 'replace',
|
|
2792
670
|
routeDirection: 'none',
|
|
2793
|
-
tab:
|
|
671
|
+
tab: this.currentTab,
|
|
2794
672
|
};
|
|
2795
673
|
}
|
|
2796
|
-
/**
|
|
2797
|
-
* A `POP` action can be triggered by the browser's back/forward
|
|
2798
|
-
* button. Both fire as POP events, so we use a forward stack to
|
|
2799
|
-
* distinguish them: when going back, we push the leaving pathname
|
|
2800
|
-
* onto the stack. When the next POP's destination matches the top
|
|
2801
|
-
* of the stack, it's a forward navigation.
|
|
2802
|
-
*/
|
|
2803
674
|
if (action === 'POP') {
|
|
2804
|
-
const currentRoute = locationHistory.current
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
forwardStack.current.pop();
|
|
2809
|
-
incomingRouteParams.current = {
|
|
2810
|
-
routeAction: 'push',
|
|
2811
|
-
routeDirection: 'forward',
|
|
2812
|
-
tab: tabToUse,
|
|
2813
|
-
};
|
|
2814
|
-
}
|
|
2815
|
-
else if (currentRoute && currentRoute.pushedByRoute) {
|
|
2816
|
-
// Back navigation. Record current location key for potential forward
|
|
2817
|
-
forwardStack.current.push(currentLocationKeyRef.current);
|
|
2818
|
-
const prevInfo = locationHistory.current.findLastLocation(currentRoute);
|
|
2819
|
-
const isMultiStepBack = checkIsMultiStepBack(prevInfo, location.pathname, locationHistory.current);
|
|
2820
|
-
if (isMultiStepBack) {
|
|
2821
|
-
const destinationInfo = locationHistory.current.findLastLocationByPathname(location.pathname);
|
|
2822
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, (destinationInfo || {})), { routeAction: 'pop', routeDirection: 'back' });
|
|
2823
|
-
}
|
|
2824
|
-
else if (prevInfo && prevInfo.pathname !== location.pathname && currentRoute.tab) {
|
|
2825
|
-
// Browser POP destination differs from within-tab back target.
|
|
2826
|
-
// Sync URL via replace, like handleNavigateBack's non-linear path (#25141).
|
|
2827
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back' });
|
|
2828
|
-
forwardStack.current = [];
|
|
2829
|
-
handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', undefined, undefined, prevInfo.tab);
|
|
2830
|
-
return;
|
|
2831
|
-
}
|
|
2832
|
-
else {
|
|
2833
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back' });
|
|
2834
|
-
}
|
|
675
|
+
const currentRoute = this.locationHistory.current();
|
|
676
|
+
if (currentRoute && currentRoute.pushedByRoute) {
|
|
677
|
+
const prevInfo = this.locationHistory.findLastLocation(currentRoute);
|
|
678
|
+
this.incomingRouteParams = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back' });
|
|
2835
679
|
}
|
|
2836
680
|
else {
|
|
2837
|
-
|
|
2838
|
-
// Still push the current location key so browser forward is detectable.
|
|
2839
|
-
forwardStack.current.push(currentLocationKeyRef.current);
|
|
2840
|
-
incomingRouteParams.current = {
|
|
681
|
+
this.incomingRouteParams = {
|
|
2841
682
|
routeAction: 'pop',
|
|
2842
683
|
routeDirection: 'none',
|
|
2843
|
-
tab:
|
|
684
|
+
tab: this.currentTab,
|
|
2844
685
|
};
|
|
2845
686
|
}
|
|
2846
687
|
}
|
|
2847
|
-
if (!incomingRouteParams
|
|
2848
|
-
|
|
2849
|
-
incomingRouteParams.current = {
|
|
688
|
+
if (!this.incomingRouteParams) {
|
|
689
|
+
this.incomingRouteParams = {
|
|
2850
690
|
routeAction: 'push',
|
|
2851
|
-
routeDirection: (state === null ||
|
|
2852
|
-
routeOptions: state === null ||
|
|
2853
|
-
tab:
|
|
691
|
+
routeDirection: ((_a = location.state) === null || _a === void 0 ? void 0 : _a.direction) || 'forward',
|
|
692
|
+
routeOptions: (_b = location.state) === null || _b === void 0 ? void 0 : _b.routerOptions,
|
|
693
|
+
tab: this.currentTab,
|
|
2854
694
|
};
|
|
2855
695
|
}
|
|
2856
696
|
}
|
|
2857
|
-
// New navigation (PUSH) invalidates browser forward history,
|
|
2858
|
-
// so clear our forward stack to stay in sync.
|
|
2859
|
-
if (action === 'PUSH') {
|
|
2860
|
-
forwardStack.current = [];
|
|
2861
|
-
}
|
|
2862
697
|
let routeInfo;
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
}
|
|
2867
|
-
/**
|
|
2868
|
-
* An existing id indicates that it's re-activating an existing route.
|
|
2869
|
-
* e.g., tab switching or navigating back to a previous route
|
|
2870
|
-
*/
|
|
2871
|
-
if ((_b = incomingRouteParams.current) === null || _b === void 0 ? void 0 : _b.id) {
|
|
2872
|
-
routeInfo = Object.assign(Object.assign({}, incomingRouteParams.current), { lastPathname: leavingLocationInfo.pathname });
|
|
2873
|
-
locationHistory.current.add(routeInfo);
|
|
2874
|
-
/**
|
|
2875
|
-
* A new route is being created since it's not re-activating
|
|
2876
|
-
* an existing route.
|
|
2877
|
-
*/
|
|
698
|
+
if ((_c = this.incomingRouteParams) === null || _c === void 0 ? void 0 : _c.id) {
|
|
699
|
+
routeInfo = Object.assign(Object.assign({}, this.incomingRouteParams), { lastPathname: leavingLocationInfo.pathname });
|
|
700
|
+
this.locationHistory.add(routeInfo);
|
|
2878
701
|
}
|
|
2879
702
|
else {
|
|
2880
|
-
const isPushed =
|
|
2881
|
-
|
|
2882
|
-
routeInfo = Object.assign(Object.assign({ id: generateId('routeInfo') }, incomingRouteParams.current), { lastPathname: leavingLocationInfo.pathname, pathname: location.pathname, search: location.search, params: ((_d = incomingRouteParams.current) === null || _d === void 0 ? void 0 : _d.params)
|
|
2883
|
-
? filterUndefinedParams(incomingRouteParams.current.params)
|
|
2884
|
-
: {}, prevRouteLastPathname: leavingLocationInfo.lastPathname });
|
|
703
|
+
const isPushed = this.incomingRouteParams.routeAction === 'push' && this.incomingRouteParams.routeDirection === 'forward';
|
|
704
|
+
routeInfo = Object.assign(Object.assign({ id: generateId('routeInfo') }, this.incomingRouteParams), { lastPathname: leavingLocationInfo.pathname, pathname: location.pathname, search: location.search, params: this.props.match.params, prevRouteLastPathname: leavingLocationInfo.lastPathname });
|
|
2885
705
|
if (isPushed) {
|
|
2886
|
-
|
|
2887
|
-
// This preserves tab context for same-tab navigation while allowing cross-tab navigation.
|
|
2888
|
-
routeInfo.tab = routeInfo.tab || leavingLocationInfo.tab;
|
|
2889
|
-
routeInfo.pushedByRoute = leavingLocationInfo.pathname;
|
|
2890
|
-
}
|
|
2891
|
-
else if (routeInfo.routeAction === 'push' &&
|
|
2892
|
-
routeInfo.routeDirection === 'none' &&
|
|
2893
|
-
routeInfo.tab === leavingLocationInfo.tab) {
|
|
2894
|
-
// Push with routerDirection="none" within the same tab (or non-tab) context.
|
|
2895
|
-
// Still needs pushedByRoute so the back button can navigate back correctly.
|
|
2896
|
-
// Cross-tab navigations with direction "none" are handled by the tab-switching
|
|
2897
|
-
// block below which has different pushedByRoute semantics.
|
|
2898
|
-
routeInfo.tab = routeInfo.tab || leavingLocationInfo.tab;
|
|
706
|
+
routeInfo.tab = leavingLocationInfo.tab;
|
|
2899
707
|
routeInfo.pushedByRoute = leavingLocationInfo.pathname;
|
|
2900
708
|
}
|
|
2901
709
|
else if (routeInfo.routeAction === 'pop') {
|
|
2902
|
-
|
|
2903
|
-
// Find the route that pushed this one.
|
|
2904
|
-
const r = locationHistory.current.findLastLocation(routeInfo);
|
|
710
|
+
const r = this.locationHistory.findLastLocation(routeInfo);
|
|
2905
711
|
routeInfo.pushedByRoute = r === null || r === void 0 ? void 0 : r.pushedByRoute;
|
|
2906
|
-
// Navigating to a new tab.
|
|
2907
712
|
}
|
|
2908
713
|
else if (routeInfo.routeAction === 'push' && routeInfo.tab !== leavingLocationInfo.tab) {
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
*/
|
|
2913
|
-
const lastRoute = locationHistory.current.getCurrentRouteInfoForTab(routeInfo.tab);
|
|
2914
|
-
/**
|
|
2915
|
-
* Tab bar switches (direction 'none') should not create cross-tab back
|
|
2916
|
-
* navigation. Only inherit pushedByRoute from the tab's own history.
|
|
2917
|
-
*/
|
|
2918
|
-
if (routeInfo.routeDirection === 'none') {
|
|
2919
|
-
routeInfo.pushedByRoute = lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.pushedByRoute;
|
|
2920
|
-
}
|
|
2921
|
-
else {
|
|
2922
|
-
routeInfo.pushedByRoute = (_e = lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.pushedByRoute) !== null && _e !== void 0 ? _e : leavingLocationInfo.pathname;
|
|
2923
|
-
}
|
|
2924
|
-
// Triggered by `navigate()` with replace or a `<Navigate />` component, etc.
|
|
714
|
+
// If we are switching tabs grab the last route info for the tab and use its pushedByRoute
|
|
715
|
+
const lastRoute = this.locationHistory.getCurrentRouteInfoForTab(routeInfo.tab);
|
|
716
|
+
routeInfo.pushedByRoute = lastRoute === null || lastRoute === void 0 ? void 0 : lastRoute.pushedByRoute;
|
|
2925
717
|
}
|
|
2926
718
|
else if (routeInfo.routeAction === 'replace') {
|
|
719
|
+
// Make sure to set the lastPathname, etc.. to the current route so the page transitions out
|
|
720
|
+
const currentRouteInfo = this.locationHistory.current();
|
|
2927
721
|
/**
|
|
2928
|
-
*
|
|
2929
|
-
*
|
|
2930
|
-
|
|
2931
|
-
const currentRouteInfo = locationHistory.current.current();
|
|
2932
|
-
/**
|
|
2933
|
-
* Special handling for `replace` to ensure correct `pushedByRoute`
|
|
2934
|
-
* and `lastPathname`.
|
|
2935
|
-
*
|
|
2936
|
-
* If going from `/home` to `/child`, then replacing from
|
|
2937
|
-
* `/child` to `/home`, we don't want the route info to
|
|
2938
|
-
* say that `/home` was pushed by `/home` which is not correct.
|
|
722
|
+
* If going from /home to /child, then replacing from
|
|
723
|
+
* /child to /home, we don't want the route info to
|
|
724
|
+
* say that /home was pushed by /home which is not correct.
|
|
2939
725
|
*/
|
|
2940
726
|
const currentPushedBy = currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.pushedByRoute;
|
|
2941
727
|
const pushedByRoute = currentPushedBy !== undefined && currentPushedBy !== routeInfo.pathname
|
|
@@ -2953,120 +739,46 @@ const IonRouter = ({ children, registerHistoryListener }) => {
|
|
|
2953
739
|
routeInfo.routeDirection = routeInfo.routeDirection || (currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.routeDirection);
|
|
2954
740
|
routeInfo.routeAnimation = routeInfo.routeAnimation || (currentRouteInfo === null || currentRouteInfo === void 0 ? void 0 : currentRouteInfo.routeAnimation);
|
|
2955
741
|
}
|
|
2956
|
-
locationHistory.
|
|
742
|
+
this.locationHistory.add(routeInfo);
|
|
2957
743
|
}
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
// This ensures the forward stack records the correct key when navigating back.
|
|
2962
|
-
currentLocationKeyRef.current = location.key;
|
|
2963
|
-
incomingRouteParams.current = null;
|
|
2964
|
-
};
|
|
2965
|
-
/**
|
|
2966
|
-
* Resets the specified tab to its initial, root route.
|
|
2967
|
-
*
|
|
2968
|
-
* @param tab The tab to reset.
|
|
2969
|
-
* @param originalHref The original href for the tab.
|
|
2970
|
-
* @param originalRouteOptions The original route options for the tab.
|
|
2971
|
-
*/
|
|
2972
|
-
const handleResetTab = (tab, originalHref, originalRouteOptions) => {
|
|
2973
|
-
const routeInfo = locationHistory.current.getFirstRouteInfoForTab(tab);
|
|
2974
|
-
if (routeInfo) {
|
|
2975
|
-
const [pathname, search] = originalHref.split('?');
|
|
2976
|
-
const newRouteInfo = Object.assign({}, routeInfo);
|
|
2977
|
-
newRouteInfo.pathname = pathname;
|
|
2978
|
-
newRouteInfo.search = search ? '?' + search : '';
|
|
2979
|
-
newRouteInfo.routeOptions = originalRouteOptions;
|
|
2980
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, newRouteInfo), { routeAction: 'pop', routeDirection: 'back' });
|
|
2981
|
-
navigate(newRouteInfo.pathname + (newRouteInfo.search || ''));
|
|
744
|
+
this.setState({
|
|
745
|
+
routeInfo,
|
|
746
|
+
});
|
|
2982
747
|
}
|
|
2983
|
-
|
|
748
|
+
this.incomingRouteParams = undefined;
|
|
749
|
+
}
|
|
2984
750
|
/**
|
|
2985
|
-
*
|
|
2986
|
-
*
|
|
2987
|
-
*
|
|
2988
|
-
*
|
|
2989
|
-
* @param routeOptions Additional route options.
|
|
751
|
+
* history@4.x uses goBack(), history@5.x uses back()
|
|
752
|
+
* TODO: If support for React Router <=5 is dropped
|
|
753
|
+
* this logic is no longer needed. We can just
|
|
754
|
+
* assume back() is available.
|
|
2990
755
|
*/
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, routeParams), { search: newSearch || '', routeOptions });
|
|
3007
|
-
navigate(routeInfo.pathname + (newSearch || ''));
|
|
3008
|
-
/**
|
|
3009
|
-
* User is navigating to a different tab.
|
|
3010
|
-
* e.g., `/tabs/home` → `/tabs/settings`
|
|
3011
|
-
*/
|
|
3012
|
-
}
|
|
3013
|
-
else {
|
|
3014
|
-
incomingRouteParams.current = Object.assign(Object.assign({}, routeParams), { pathname, search: search ? '?' + search : '', routeOptions });
|
|
3015
|
-
navigate(pathname + (search ? '?' + search : ''));
|
|
3016
|
-
}
|
|
3017
|
-
// User has not navigated to this tab before.
|
|
756
|
+
handleNativeBack() {
|
|
757
|
+
const history = this.props.history;
|
|
758
|
+
const goBack = history.goBack || history.back;
|
|
759
|
+
goBack();
|
|
760
|
+
}
|
|
761
|
+
handleNavigate(path, routeAction, routeDirection, routeAnimation, routeOptions, tab) {
|
|
762
|
+
this.incomingRouteParams = Object.assign(this.incomingRouteParams || {}, {
|
|
763
|
+
routeAction,
|
|
764
|
+
routeDirection,
|
|
765
|
+
routeOptions,
|
|
766
|
+
routeAnimation,
|
|
767
|
+
tab,
|
|
768
|
+
});
|
|
769
|
+
if (routeAction === 'push') {
|
|
770
|
+
this.props.history.push(path);
|
|
3018
771
|
}
|
|
3019
772
|
else {
|
|
3020
|
-
|
|
3021
|
-
handleNavigate(fullPath, 'push', 'none', undefined, routeOptions, tab);
|
|
3022
|
-
}
|
|
3023
|
-
};
|
|
3024
|
-
/**
|
|
3025
|
-
* Set the current active tab in `locationHistory`.
|
|
3026
|
-
* This is crucial for maintaining tab history since each tab has
|
|
3027
|
-
* its own navigation stack.
|
|
3028
|
-
*
|
|
3029
|
-
* @param tab The tab to set as active.
|
|
3030
|
-
*/
|
|
3031
|
-
const handleSetCurrentTab = (tab, _routeInfo) => {
|
|
3032
|
-
currentTab.current = tab;
|
|
3033
|
-
const current = locationHistory.current.current();
|
|
3034
|
-
if (!current) {
|
|
3035
|
-
// locationHistory not yet seeded (e.g., called during initial render
|
|
3036
|
-
// before mount effect). The mount effect will seed the correct entry.
|
|
3037
|
-
return;
|
|
3038
|
-
}
|
|
3039
|
-
const ri = Object.assign({}, current);
|
|
3040
|
-
if (ri.tab !== tab) {
|
|
3041
|
-
ri.tab = tab;
|
|
3042
|
-
locationHistory.current.update(ri);
|
|
773
|
+
this.props.history.replace(path);
|
|
3043
774
|
}
|
|
3044
|
-
}
|
|
3045
|
-
|
|
3046
|
-
* Handles the native back button press.
|
|
3047
|
-
* It's usually called when a user presses the platform-native back action.
|
|
3048
|
-
*/
|
|
3049
|
-
const handleNativeBack = () => {
|
|
3050
|
-
navigate(-1);
|
|
3051
|
-
};
|
|
3052
|
-
/**
|
|
3053
|
-
* Used to manage the back navigation within the Ionic React's routing
|
|
3054
|
-
* system. It's deeply integrated with Ionic's view lifecycle, animations,
|
|
3055
|
-
* and its custom history tracking (`locationHistory`) to provide a
|
|
3056
|
-
* native-like transition and maintain correct application state.
|
|
3057
|
-
*
|
|
3058
|
-
* @param defaultHref The fallback URL to navigate to if there's no
|
|
3059
|
-
* previous entry in the `locationHistory` stack.
|
|
3060
|
-
* @param routeAnimation A custom animation builder to override the
|
|
3061
|
-
* default "back" animation.
|
|
3062
|
-
*/
|
|
3063
|
-
const handleNavigateBack = (defaultHref = '/', routeAnimation) => {
|
|
775
|
+
}
|
|
776
|
+
handleNavigateBack(defaultHref = '/', routeAnimation) {
|
|
3064
777
|
const config = getConfig();
|
|
3065
778
|
defaultHref = defaultHref ? defaultHref : config && config.get('backButtonDefaultHref');
|
|
3066
|
-
const routeInfo = locationHistory.current
|
|
3067
|
-
// It's a linear navigation.
|
|
779
|
+
const routeInfo = this.locationHistory.current();
|
|
3068
780
|
if (routeInfo && routeInfo.pushedByRoute) {
|
|
3069
|
-
const prevInfo = locationHistory.
|
|
781
|
+
const prevInfo = this.locationHistory.findLastLocation(routeInfo);
|
|
3070
782
|
if (prevInfo) {
|
|
3071
783
|
/**
|
|
3072
784
|
* This needs to be passed to handleNavigate
|
|
@@ -3074,243 +786,160 @@ const IonRouter = ({ children, registerHistoryListener }) => {
|
|
|
3074
786
|
* will be overridden.
|
|
3075
787
|
*/
|
|
3076
788
|
const incomingAnimation = routeAnimation || routeInfo.routeAnimation;
|
|
3077
|
-
incomingRouteParams
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
forwardStack.current.push(currentLocationKeyRef.current);
|
|
3087
|
-
navigate(-1);
|
|
3088
|
-
}
|
|
3089
|
-
else {
|
|
789
|
+
this.incomingRouteParams = Object.assign(Object.assign({}, prevInfo), { routeAction: 'pop', routeDirection: 'back', routeAnimation: incomingAnimation });
|
|
790
|
+
if (routeInfo.lastPathname === routeInfo.pushedByRoute ||
|
|
791
|
+
/**
|
|
792
|
+
* We need to exclude tab switches/tab
|
|
793
|
+
* context changes here because tabbed
|
|
794
|
+
* navigation is not linear, but router.back()
|
|
795
|
+
* will go back in a linear fashion.
|
|
796
|
+
*/
|
|
797
|
+
(prevInfo.pathname === routeInfo.pushedByRoute && routeInfo.tab === '' && prevInfo.tab === '')) {
|
|
3090
798
|
/**
|
|
3091
|
-
*
|
|
3092
|
-
*
|
|
3093
|
-
*
|
|
3094
|
-
*
|
|
799
|
+
* history@4.x uses goBack(), history@5.x uses back()
|
|
800
|
+
* TODO: If support for React Router <=5 is dropped
|
|
801
|
+
* this logic is no longer needed. We can just
|
|
802
|
+
* assume back() is available.
|
|
3095
803
|
*/
|
|
3096
|
-
|
|
3097
|
-
|
|
804
|
+
const history = this.props.history;
|
|
805
|
+
const goBack = history.goBack || history.back;
|
|
806
|
+
goBack();
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
this.handleNavigate(prevInfo.pathname + (prevInfo.search || ''), 'pop', 'back', incomingAnimation);
|
|
3098
810
|
}
|
|
3099
|
-
/**
|
|
3100
|
-
* `pushedByRoute` exists, but no corresponding previous entry in
|
|
3101
|
-
* the history stack.
|
|
3102
|
-
*/
|
|
3103
811
|
}
|
|
3104
812
|
else {
|
|
3105
|
-
handleNavigate(defaultHref, 'pop', 'back', routeAnimation);
|
|
813
|
+
this.handleNavigate(defaultHref, 'pop', 'back', routeAnimation);
|
|
3106
814
|
}
|
|
3107
|
-
/**
|
|
3108
|
-
* No `pushedByRoute` (e.g., initial page load or tab root).
|
|
3109
|
-
* Tabs with no back history should not navigate.
|
|
3110
|
-
*/
|
|
3111
815
|
}
|
|
3112
816
|
else {
|
|
3113
|
-
|
|
3114
|
-
return;
|
|
3115
|
-
}
|
|
3116
|
-
handleNavigate(defaultHref, 'pop', 'back', routeAnimation);
|
|
817
|
+
this.handleNavigate(defaultHref, 'pop', 'back', routeAnimation);
|
|
3117
818
|
}
|
|
3118
|
-
}
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
* @param routeOptions Additional options for the route.
|
|
3128
|
-
* @param tab The tab to navigate to, if applicable.
|
|
3129
|
-
*/
|
|
3130
|
-
const handleNavigate = (path, routeAction, routeDirection, routeAnimation, routeOptions, tab) => {
|
|
3131
|
-
var _a;
|
|
3132
|
-
const normalizedRouteDirection = routeAction === 'push' && routeDirection === undefined ? 'forward' : routeDirection;
|
|
3133
|
-
// When navigating from tabs context, we need to determine if the destination
|
|
3134
|
-
// is also within tabs. If not, we should clear the tab context.
|
|
3135
|
-
let navigationTab = tab;
|
|
3136
|
-
// If no explicit tab is provided and we're in a tab context,
|
|
3137
|
-
// check if the destination path is outside of the current tab context.
|
|
3138
|
-
// Uses history-based tab detection instead of URL pattern matching,
|
|
3139
|
-
// so it works with any tab URL structure.
|
|
3140
|
-
if (!tab && currentTab.current && path) {
|
|
3141
|
-
// Check if destination was previously visited in a tab context
|
|
3142
|
-
const destinationTab = locationHistory.current.findTabForPathname(path);
|
|
3143
|
-
if (destinationTab) {
|
|
3144
|
-
// Previously visited as a tab route - use the known tab
|
|
3145
|
-
navigationTab = destinationTab;
|
|
3146
|
-
}
|
|
3147
|
-
else {
|
|
3148
|
-
// New destination - check if it's a child of the current tab's root path
|
|
3149
|
-
const tabFirstRoute = locationHistory.current.getFirstRouteInfoForTab(currentTab.current);
|
|
3150
|
-
if (tabFirstRoute) {
|
|
3151
|
-
const tabRootPath = tabFirstRoute.pathname;
|
|
3152
|
-
if (path === tabRootPath || path.startsWith(tabRootPath + '/')) {
|
|
3153
|
-
// Still within the current tab's path hierarchy
|
|
3154
|
-
navigationTab = currentTab.current;
|
|
3155
|
-
}
|
|
3156
|
-
else {
|
|
3157
|
-
// Destination is outside the current tab context
|
|
3158
|
-
currentTab.current = undefined;
|
|
3159
|
-
navigationTab = undefined;
|
|
3160
|
-
}
|
|
3161
|
-
}
|
|
3162
|
-
}
|
|
819
|
+
}
|
|
820
|
+
handleResetTab(tab, originalHref, originalRouteOptions) {
|
|
821
|
+
const routeInfo = this.locationHistory.getFirstRouteInfoForTab(tab);
|
|
822
|
+
if (routeInfo) {
|
|
823
|
+
const newRouteInfo = Object.assign({}, routeInfo);
|
|
824
|
+
newRouteInfo.pathname = originalHref;
|
|
825
|
+
newRouteInfo.routeOptions = originalRouteOptions;
|
|
826
|
+
this.incomingRouteParams = Object.assign(Object.assign({}, newRouteInfo), { routeAction: 'pop', routeDirection: 'back' });
|
|
827
|
+
this.props.history.push(newRouteInfo.pathname + (newRouteInfo.search || ''));
|
|
3163
828
|
}
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
addViewItem: viewStack.current.add,
|
|
3180
|
-
unMountViewItem: viewStack.current.remove,
|
|
3181
|
-
};
|
|
3182
|
-
return (React.createElement(RouteManagerContext.Provider, { value: routeMangerContextValue },
|
|
3183
|
-
React.createElement(NavManager, { ionRoute: IonRouteInner, stackManager: StackManager, routeInfo: routeInfo, onNativeBack: handleNativeBack, onNavigateBack: handleNavigateBack, onNavigate: handleNavigate, onSetCurrentTab: handleSetCurrentTab, onChangeTab: handleChangeTab, onResetTab: handleResetTab, locationHistory: locationHistory.current }, children)));
|
|
3184
|
-
};
|
|
829
|
+
}
|
|
830
|
+
handleSetCurrentTab(tab) {
|
|
831
|
+
this.currentTab = tab;
|
|
832
|
+
const ri = Object.assign({}, this.locationHistory.current());
|
|
833
|
+
if (ri.tab !== tab) {
|
|
834
|
+
ri.tab = tab;
|
|
835
|
+
this.locationHistory.update(ri);
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
render() {
|
|
839
|
+
return (React.createElement(RouteManagerContext.Provider, { value: this.routeMangerContextState },
|
|
840
|
+
React.createElement(NavManager, { ionRoute: IonRouteInner, ionRedirect: {}, stackManager: StackManager, routeInfo: this.state.routeInfo, onNativeBack: this.handleNativeBack, onNavigateBack: this.handleNavigateBack, onNavigate: this.handleNavigate, onSetCurrentTab: this.handleSetCurrentTab, onChangeTab: this.handleChangeTab, onResetTab: this.handleResetTab, locationHistory: this.locationHistory }, this.props.children)));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
const IonRouter = withRouter(IonRouterInner);
|
|
3185
844
|
IonRouter.displayName = 'IonRouter';
|
|
3186
845
|
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
* `useLocation` and `useNavigationType` are called within the valid
|
|
3196
|
-
* context of a `<BrowserRouter>`.
|
|
3197
|
-
*
|
|
3198
|
-
* It was split from `IonReactRouter` because these hooks must be
|
|
3199
|
-
* descendants of a `<Router>` component, which `BrowserRouter` provides.
|
|
3200
|
-
*/
|
|
3201
|
-
const RouterContent$2 = ({ children }) => {
|
|
3202
|
-
const location = useLocation();
|
|
3203
|
-
const navigationType = useNavigationType();
|
|
3204
|
-
const historyListenHandler = useRef();
|
|
3205
|
-
const registerHistoryListener = useCallback((cb) => {
|
|
3206
|
-
historyListenHandler.current = cb;
|
|
3207
|
-
}, []);
|
|
846
|
+
class IonReactRouter extends React.Component {
|
|
847
|
+
constructor(props) {
|
|
848
|
+
super(props);
|
|
849
|
+
const { history } = props, rest = __rest(props, ["history"]);
|
|
850
|
+
this.history = history || createBrowserHistory(rest);
|
|
851
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
852
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
853
|
+
}
|
|
3208
854
|
/**
|
|
3209
|
-
*
|
|
3210
|
-
*
|
|
3211
|
-
*
|
|
3212
|
-
*
|
|
3213
|
-
*
|
|
3214
|
-
*
|
|
3215
|
-
*
|
|
3216
|
-
* @param loc The current browser history location object.
|
|
3217
|
-
* @param act The type of navigation action ('PUSH', 'POP', or
|
|
3218
|
-
* 'REPLACE').
|
|
855
|
+
* history@4.x passes separate location and action
|
|
856
|
+
* params. history@5.x passes location and action
|
|
857
|
+
* together as a single object.
|
|
858
|
+
* TODO: If support for React Router <=5 is dropped
|
|
859
|
+
* this logic is no longer needed. We can just assume
|
|
860
|
+
* a single object with both location and action.
|
|
3219
861
|
*/
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
862
|
+
handleHistoryChange(location, action) {
|
|
863
|
+
const locationValue = location.location || location;
|
|
864
|
+
const actionValue = location.action || action;
|
|
865
|
+
if (this.historyListenHandler) {
|
|
866
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
3223
867
|
}
|
|
3224
|
-
}
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
}
|
|
3228
|
-
|
|
3229
|
-
};
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
};
|
|
868
|
+
}
|
|
869
|
+
registerHistoryListener(cb) {
|
|
870
|
+
this.historyListenHandler = cb;
|
|
871
|
+
}
|
|
872
|
+
render() {
|
|
873
|
+
const _a = this.props, { children } = _a, props = __rest(_a, ["children"]);
|
|
874
|
+
return (React.createElement(Router, Object.assign({ history: this.history }, props),
|
|
875
|
+
React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children)));
|
|
876
|
+
}
|
|
877
|
+
}
|
|
3235
878
|
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
const navigationType = useNavigationType$1();
|
|
3244
|
-
const historyListenHandler = useRef();
|
|
3245
|
-
const registerHistoryListener = useCallback((cb) => {
|
|
3246
|
-
historyListenHandler.current = cb;
|
|
3247
|
-
}, []);
|
|
879
|
+
class IonReactMemoryRouter extends React.Component {
|
|
880
|
+
constructor(props) {
|
|
881
|
+
super(props);
|
|
882
|
+
this.history = props.history;
|
|
883
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
884
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
885
|
+
}
|
|
3248
886
|
/**
|
|
3249
|
-
*
|
|
3250
|
-
*
|
|
3251
|
-
*
|
|
3252
|
-
*
|
|
3253
|
-
*
|
|
3254
|
-
*
|
|
3255
|
-
*
|
|
3256
|
-
* @param location The current browser history location object.
|
|
3257
|
-
* @param action The type of navigation action ('PUSH', 'POP', or
|
|
3258
|
-
* 'REPLACE').
|
|
887
|
+
* history@4.x passes separate location and action
|
|
888
|
+
* params. history@5.x passes location and action
|
|
889
|
+
* together as a single object.
|
|
890
|
+
* TODO: If support for React Router <=5 is dropped
|
|
891
|
+
* this logic is no longer needed. We can just assume
|
|
892
|
+
* a single object with both location and action.
|
|
3259
893
|
*/
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
894
|
+
handleHistoryChange(location, action) {
|
|
895
|
+
const locationValue = location.location || location;
|
|
896
|
+
const actionValue = location.action || action;
|
|
897
|
+
if (this.historyListenHandler) {
|
|
898
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
3263
899
|
}
|
|
3264
|
-
}
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
}
|
|
3268
|
-
|
|
3269
|
-
};
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
};
|
|
900
|
+
}
|
|
901
|
+
registerHistoryListener(cb) {
|
|
902
|
+
this.historyListenHandler = cb;
|
|
903
|
+
}
|
|
904
|
+
render() {
|
|
905
|
+
const _a = this.props, { children } = _a, props = __rest(_a, ["children"]);
|
|
906
|
+
return (React.createElement(Router$1, Object.assign({}, props),
|
|
907
|
+
React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children)));
|
|
908
|
+
}
|
|
909
|
+
}
|
|
3275
910
|
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
const registerHistoryListener = useCallback((cb) => {
|
|
3285
|
-
historyListenHandler.current = cb;
|
|
3286
|
-
}, []);
|
|
911
|
+
class IonReactHashRouter extends React.Component {
|
|
912
|
+
constructor(props) {
|
|
913
|
+
super(props);
|
|
914
|
+
const { history } = props, rest = __rest(props, ["history"]);
|
|
915
|
+
this.history = history || createHashHistory(rest);
|
|
916
|
+
this.history.listen(this.handleHistoryChange.bind(this));
|
|
917
|
+
this.registerHistoryListener = this.registerHistoryListener.bind(this);
|
|
918
|
+
}
|
|
3287
919
|
/**
|
|
3288
|
-
*
|
|
3289
|
-
*
|
|
3290
|
-
*
|
|
3291
|
-
*
|
|
3292
|
-
*
|
|
3293
|
-
*
|
|
3294
|
-
*
|
|
3295
|
-
* @param location The current browser history location object.
|
|
3296
|
-
* @param action The type of navigation action ('PUSH', 'POP', or
|
|
3297
|
-
* 'REPLACE').
|
|
920
|
+
* history@4.x passes separate location and action
|
|
921
|
+
* params. history@5.x passes location and action
|
|
922
|
+
* together as a single object.
|
|
923
|
+
* TODO: If support for React Router <=5 is dropped
|
|
924
|
+
* this logic is no longer needed. We can just assume
|
|
925
|
+
* a single object with both location and action.
|
|
3298
926
|
*/
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
927
|
+
handleHistoryChange(location, action) {
|
|
928
|
+
const locationValue = location.location || location;
|
|
929
|
+
const actionValue = location.action || action;
|
|
930
|
+
if (this.historyListenHandler) {
|
|
931
|
+
this.historyListenHandler(locationValue, actionValue);
|
|
3302
932
|
}
|
|
3303
|
-
}
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
}
|
|
3307
|
-
|
|
3308
|
-
};
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
};
|
|
933
|
+
}
|
|
934
|
+
registerHistoryListener(cb) {
|
|
935
|
+
this.historyListenHandler = cb;
|
|
936
|
+
}
|
|
937
|
+
render() {
|
|
938
|
+
const _a = this.props, { children } = _a, props = __rest(_a, ["children"]);
|
|
939
|
+
return (React.createElement(Router, Object.assign({ history: this.history }, props),
|
|
940
|
+
React.createElement(IonRouter, { registerHistoryListener: this.registerHistoryListener }, children)));
|
|
941
|
+
}
|
|
942
|
+
}
|
|
3314
943
|
|
|
3315
944
|
export { IonReactHashRouter, IonReactMemoryRouter, IonReactRouter };
|
|
3316
945
|
//# sourceMappingURL=index.js.map
|