@ionic/react-router 9.0.13-dev.11795137446.17ffb6e9 → 9.0.13-dev.11795197602.11ba74b4
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 +24 -11
- package/dist/index.js.map +1 -1
- package/dist/types/ReactRouter/IonReactMemoryRouter.d.ts +1 -1
- package/dist/types/ReactRouter/IonRouter.d.ts +1 -2
- package/dist/types/ReactRouter/utils/pathMatching.d.ts +1 -1
- package/dist/types/ReactRouter/utils/transitionDefaults.d.ts +10 -0
- package/package.json +16 -9
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import React, { useRef, useState, useEffect, useCallback } from 'react';
|
|
2
|
-
import { Route, matchPath as matchPath$1, Routes, Navigate, UNSAFE_RouteContext, matchRoutes, useLocation, useNavigate, BrowserRouter, useNavigationType, HashRouter } from 'react-router-dom';
|
|
2
|
+
import { Route, matchPath as matchPath$1, Routes, Navigate, UNSAFE_RouteContext, matchRoutes, useLocation, useNavigate, BrowserRouter, useNavigationType, MemoryRouter, HashRouter } from 'react-router-dom';
|
|
3
3
|
import { IonRoute, ViewStacks, generateId, ViewLifeCycleManager, StackContext, createDebugLogger, RouteManagerContext, getConfig, LocationHistory, NavManager } from '@ionic/react';
|
|
4
4
|
import { LIFECYCLE_WILL_LEAVE, LIFECYCLE_DID_LEAVE, LIFECYCLE_WILL_ENTER, LIFECYCLE_DID_ENTER } from '@ionic/core/components';
|
|
5
|
-
import { MemoryRouter, useLocation as useLocation$1, useNavigationType as useNavigationType$1 } from 'react-router';
|
|
6
5
|
|
|
7
6
|
const IonRouteInner = ({ path, index, caseSensitive, element }) => {
|
|
8
7
|
return React.createElement(Route, { path: path, index: index, caseSensitive: caseSensitive, element: element });
|
|
@@ -646,14 +645,16 @@ const getFallbackParamsFromViewItems = (allViewItems, currentOutletId, currentPa
|
|
|
646
645
|
return params;
|
|
647
646
|
};
|
|
648
647
|
/**
|
|
649
|
-
* Builds the matches array for RouteContext.
|
|
648
|
+
* Builds the matches array for RouteContext. The leaf `pathname` uses the absolute base,
|
|
649
|
+
* because the raw match is relative for a route without a leading slash, which breaks
|
|
650
|
+
* relative links, and includes a splat's tail, which loops an index `<Navigate>`.
|
|
650
651
|
*/
|
|
651
|
-
const buildContextMatches = (parentMatches, combinedParams,
|
|
652
|
+
const buildContextMatches = (parentMatches, combinedParams, absolutePathnameBase, viewItem, routeElement, componentElement) => {
|
|
652
653
|
return [
|
|
653
654
|
...parentMatches,
|
|
654
655
|
{
|
|
655
656
|
params: combinedParams,
|
|
656
|
-
pathname:
|
|
657
|
+
pathname: absolutePathnameBase,
|
|
657
658
|
pathnameBase: absolutePathnameBase,
|
|
658
659
|
route: {
|
|
659
660
|
id: viewItem.id,
|
|
@@ -1061,7 +1062,7 @@ class ReactRouterViewStack extends ViewStacks {
|
|
|
1061
1062
|
const combinedParams = { ...accumulatedParentParams, ...(routeMatch?.params ?? {}) };
|
|
1062
1063
|
const parentPathnameBase = parentMatches.length > 0 ? parentMatches[parentMatches.length - 1].pathnameBase : '/';
|
|
1063
1064
|
const absolutePathnameBase = computeAbsolutePathnameBase(routeElement, routeMatch, parentPathnameBase, routeInfo.pathname);
|
|
1064
|
-
const contextMatches = buildContextMatches(parentMatches, combinedParams,
|
|
1065
|
+
const contextMatches = buildContextMatches(parentMatches, combinedParams, absolutePathnameBase, viewItem, routeElement, componentElement);
|
|
1065
1066
|
const routeContextValue = parentContext
|
|
1066
1067
|
? { ...parentContext, matches: contextMatches }
|
|
1067
1068
|
: { outlet: null, matches: contextMatches, isDataRoute: false };
|
|
@@ -3774,6 +3775,18 @@ const IonRouter = ({ children, registerHistoryListener }) => {
|
|
|
3774
3775
|
};
|
|
3775
3776
|
IonRouter.displayName = 'IonRouter';
|
|
3776
3777
|
|
|
3778
|
+
/**
|
|
3779
|
+
* Defaults React Router 7's `useTransitions` to `false`, since a transition can defer the
|
|
3780
|
+
* commit past Ionic's page-visible signal. React Router 6 ignores the prop.
|
|
3781
|
+
*
|
|
3782
|
+
* Uses `??` instead of spreading a default first, because an explicit
|
|
3783
|
+
* `useTransitions={undefined}` would override it and React Router reads that as on.
|
|
3784
|
+
*/
|
|
3785
|
+
const withTransitionDefaults = (props) => {
|
|
3786
|
+
const { useTransitions } = props;
|
|
3787
|
+
return { ...props, useTransitions: useTransitions ?? false };
|
|
3788
|
+
};
|
|
3789
|
+
|
|
3777
3790
|
/**
|
|
3778
3791
|
* `IonReactRouter` facilitates the integration of Ionic's specific
|
|
3779
3792
|
* navigation and UI management with the standard React Router mechanisms,
|
|
@@ -3818,7 +3831,7 @@ const RouterContent$2 = ({ children }) => {
|
|
|
3818
3831
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3819
3832
|
};
|
|
3820
3833
|
const IonReactRouter = ({ children, ...browserRouterProps }) => {
|
|
3821
|
-
return (React.createElement(BrowserRouter, { ...browserRouterProps },
|
|
3834
|
+
return (React.createElement(BrowserRouter, { ...withTransitionDefaults(browserRouterProps) },
|
|
3822
3835
|
React.createElement(RouterContent$2, null, children)));
|
|
3823
3836
|
};
|
|
3824
3837
|
|
|
@@ -3828,8 +3841,8 @@ const IonReactRouter = ({ children, ...browserRouterProps }) => {
|
|
|
3828
3841
|
* isn't available or desirable.
|
|
3829
3842
|
*/
|
|
3830
3843
|
const RouterContent$1 = ({ children }) => {
|
|
3831
|
-
const location = useLocation
|
|
3832
|
-
const navigationType = useNavigationType
|
|
3844
|
+
const location = useLocation();
|
|
3845
|
+
const navigationType = useNavigationType();
|
|
3833
3846
|
const historyListenHandler = useRef();
|
|
3834
3847
|
const registerHistoryListener = useCallback((cb) => {
|
|
3835
3848
|
historyListenHandler.current = cb;
|
|
@@ -3857,7 +3870,7 @@ const RouterContent$1 = ({ children }) => {
|
|
|
3857
3870
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3858
3871
|
};
|
|
3859
3872
|
const IonReactMemoryRouter = ({ children, ...routerProps }) => {
|
|
3860
|
-
return (React.createElement(MemoryRouter, { ...routerProps },
|
|
3873
|
+
return (React.createElement(MemoryRouter, { ...withTransitionDefaults(routerProps) },
|
|
3861
3874
|
React.createElement(RouterContent$1, null, children)));
|
|
3862
3875
|
};
|
|
3863
3876
|
|
|
@@ -3895,7 +3908,7 @@ const RouterContent = ({ children }) => {
|
|
|
3895
3908
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3896
3909
|
};
|
|
3897
3910
|
const IonReactHashRouter = ({ children, ...routerProps }) => {
|
|
3898
|
-
return (React.createElement(HashRouter, { ...routerProps },
|
|
3911
|
+
return (React.createElement(HashRouter, { ...withTransitionDefaults(routerProps) },
|
|
3899
3912
|
React.createElement(RouterContent, null, children)));
|
|
3900
3913
|
};
|
|
3901
3914
|
|