@ionic/react-router 9.0.9 → 9.0.10-dev.11793383958.19a7d413
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, createDebugLogger, StackContext, 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,
|
|
@@ -1048,7 +1049,7 @@ class ReactRouterViewStack extends ViewStacks {
|
|
|
1048
1049
|
const combinedParams = { ...accumulatedParentParams, ...(routeMatch?.params ?? {}) };
|
|
1049
1050
|
const parentPathnameBase = parentMatches.length > 0 ? parentMatches[parentMatches.length - 1].pathnameBase : '/';
|
|
1050
1051
|
const absolutePathnameBase = computeAbsolutePathnameBase(routeElement, routeMatch, parentPathnameBase, routeInfo.pathname);
|
|
1051
|
-
const contextMatches = buildContextMatches(parentMatches, combinedParams,
|
|
1052
|
+
const contextMatches = buildContextMatches(parentMatches, combinedParams, absolutePathnameBase, viewItem, routeElement, componentElement);
|
|
1052
1053
|
const routeContextValue = parentContext
|
|
1053
1054
|
? { ...parentContext, matches: contextMatches }
|
|
1054
1055
|
: { outlet: null, matches: contextMatches, isDataRoute: false };
|
|
@@ -3754,6 +3755,18 @@ const IonRouter = ({ children, registerHistoryListener }) => {
|
|
|
3754
3755
|
};
|
|
3755
3756
|
IonRouter.displayName = 'IonRouter';
|
|
3756
3757
|
|
|
3758
|
+
/**
|
|
3759
|
+
* Defaults React Router 7's `useTransitions` to `false`, since a transition can defer the
|
|
3760
|
+
* commit past Ionic's page-visible signal. React Router 6 ignores the prop.
|
|
3761
|
+
*
|
|
3762
|
+
* Uses `??` instead of spreading a default first, because an explicit
|
|
3763
|
+
* `useTransitions={undefined}` would override it and React Router reads that as on.
|
|
3764
|
+
*/
|
|
3765
|
+
const withTransitionDefaults = (props) => {
|
|
3766
|
+
const { useTransitions } = props;
|
|
3767
|
+
return { ...props, useTransitions: useTransitions ?? false };
|
|
3768
|
+
};
|
|
3769
|
+
|
|
3757
3770
|
/**
|
|
3758
3771
|
* `IonReactRouter` facilitates the integration of Ionic's specific
|
|
3759
3772
|
* navigation and UI management with the standard React Router mechanisms,
|
|
@@ -3798,7 +3811,7 @@ const RouterContent$2 = ({ children }) => {
|
|
|
3798
3811
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3799
3812
|
};
|
|
3800
3813
|
const IonReactRouter = ({ children, ...browserRouterProps }) => {
|
|
3801
|
-
return (React.createElement(BrowserRouter, { ...browserRouterProps },
|
|
3814
|
+
return (React.createElement(BrowserRouter, { ...withTransitionDefaults(browserRouterProps) },
|
|
3802
3815
|
React.createElement(RouterContent$2, null, children)));
|
|
3803
3816
|
};
|
|
3804
3817
|
|
|
@@ -3808,8 +3821,8 @@ const IonReactRouter = ({ children, ...browserRouterProps }) => {
|
|
|
3808
3821
|
* isn't available or desirable.
|
|
3809
3822
|
*/
|
|
3810
3823
|
const RouterContent$1 = ({ children }) => {
|
|
3811
|
-
const location = useLocation
|
|
3812
|
-
const navigationType = useNavigationType
|
|
3824
|
+
const location = useLocation();
|
|
3825
|
+
const navigationType = useNavigationType();
|
|
3813
3826
|
const historyListenHandler = useRef();
|
|
3814
3827
|
const registerHistoryListener = useCallback((cb) => {
|
|
3815
3828
|
historyListenHandler.current = cb;
|
|
@@ -3837,7 +3850,7 @@ const RouterContent$1 = ({ children }) => {
|
|
|
3837
3850
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3838
3851
|
};
|
|
3839
3852
|
const IonReactMemoryRouter = ({ children, ...routerProps }) => {
|
|
3840
|
-
return (React.createElement(MemoryRouter, { ...routerProps },
|
|
3853
|
+
return (React.createElement(MemoryRouter, { ...withTransitionDefaults(routerProps) },
|
|
3841
3854
|
React.createElement(RouterContent$1, null, children)));
|
|
3842
3855
|
};
|
|
3843
3856
|
|
|
@@ -3875,7 +3888,7 @@ const RouterContent = ({ children }) => {
|
|
|
3875
3888
|
return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
|
|
3876
3889
|
};
|
|
3877
3890
|
const IonReactHashRouter = ({ children, ...routerProps }) => {
|
|
3878
|
-
return (React.createElement(HashRouter, { ...routerProps },
|
|
3891
|
+
return (React.createElement(HashRouter, { ...withTransitionDefaults(routerProps) },
|
|
3879
3892
|
React.createElement(RouterContent, null, children)));
|
|
3880
3893
|
};
|
|
3881
3894
|
|