@ionic/react-router 9.0.6 → 9.0.7-dev.11790792026.1963eab3

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 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 });
@@ -622,14 +621,16 @@ const getFallbackParamsFromViewItems = (allViewItems, currentOutletId, currentPa
622
621
  return params;
623
622
  };
624
623
  /**
625
- * Builds the matches array for RouteContext.
624
+ * Builds the matches array for RouteContext. The leaf `pathname` uses the absolute base,
625
+ * because the raw match is relative for a route without a leading slash, which breaks
626
+ * relative links, and includes a splat's tail, which loops an index `<Navigate>`.
626
627
  */
627
- const buildContextMatches = (parentMatches, combinedParams, routeMatch, routeInfoPathname, absolutePathnameBase, viewItem, routeElement, componentElement) => {
628
+ const buildContextMatches = (parentMatches, combinedParams, absolutePathnameBase, viewItem, routeElement, componentElement) => {
628
629
  return [
629
630
  ...parentMatches,
630
631
  {
631
632
  params: combinedParams,
632
- pathname: routeMatch?.pathname || routeInfoPathname,
633
+ pathname: absolutePathnameBase,
633
634
  pathnameBase: absolutePathnameBase,
634
635
  route: {
635
636
  id: viewItem.id,
@@ -982,7 +983,7 @@ class ReactRouterViewStack extends ViewStacks {
982
983
  const combinedParams = { ...accumulatedParentParams, ...(routeMatch?.params ?? {}) };
983
984
  const parentPathnameBase = parentMatches.length > 0 ? parentMatches[parentMatches.length - 1].pathnameBase : '/';
984
985
  const absolutePathnameBase = computeAbsolutePathnameBase(routeElement, routeMatch, parentPathnameBase, routeInfo.pathname);
985
- const contextMatches = buildContextMatches(parentMatches, combinedParams, routeMatch, routeInfo.pathname, absolutePathnameBase, viewItem, routeElement, componentElement);
986
+ const contextMatches = buildContextMatches(parentMatches, combinedParams, absolutePathnameBase, viewItem, routeElement, componentElement);
986
987
  const routeContextValue = parentContext
987
988
  ? { ...parentContext, matches: contextMatches }
988
989
  : { outlet: null, matches: contextMatches, isDataRoute: false };
@@ -3708,6 +3709,18 @@ const IonRouter = ({ children, registerHistoryListener }) => {
3708
3709
  };
3709
3710
  IonRouter.displayName = 'IonRouter';
3710
3711
 
3712
+ /**
3713
+ * Defaults React Router 7's `useTransitions` to `false`, since a transition can defer the
3714
+ * commit past Ionic's page-visible signal. React Router 6 ignores the prop.
3715
+ *
3716
+ * Uses `??` instead of spreading a default first, because an explicit
3717
+ * `useTransitions={undefined}` would override it and React Router reads that as on.
3718
+ */
3719
+ const withTransitionDefaults = (props) => {
3720
+ const { useTransitions } = props;
3721
+ return { ...props, useTransitions: useTransitions ?? false };
3722
+ };
3723
+
3711
3724
  /**
3712
3725
  * `IonReactRouter` facilitates the integration of Ionic's specific
3713
3726
  * navigation and UI management with the standard React Router mechanisms,
@@ -3752,7 +3765,7 @@ const RouterContent$2 = ({ children }) => {
3752
3765
  return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
3753
3766
  };
3754
3767
  const IonReactRouter = ({ children, ...browserRouterProps }) => {
3755
- return (React.createElement(BrowserRouter, { ...browserRouterProps },
3768
+ return (React.createElement(BrowserRouter, { ...withTransitionDefaults(browserRouterProps) },
3756
3769
  React.createElement(RouterContent$2, null, children)));
3757
3770
  };
3758
3771
 
@@ -3762,8 +3775,8 @@ const IonReactRouter = ({ children, ...browserRouterProps }) => {
3762
3775
  * isn't available or desirable.
3763
3776
  */
3764
3777
  const RouterContent$1 = ({ children }) => {
3765
- const location = useLocation$1();
3766
- const navigationType = useNavigationType$1();
3778
+ const location = useLocation();
3779
+ const navigationType = useNavigationType();
3767
3780
  const historyListenHandler = useRef();
3768
3781
  const registerHistoryListener = useCallback((cb) => {
3769
3782
  historyListenHandler.current = cb;
@@ -3791,7 +3804,7 @@ const RouterContent$1 = ({ children }) => {
3791
3804
  return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
3792
3805
  };
3793
3806
  const IonReactMemoryRouter = ({ children, ...routerProps }) => {
3794
- return (React.createElement(MemoryRouter, { ...routerProps },
3807
+ return (React.createElement(MemoryRouter, { ...withTransitionDefaults(routerProps) },
3795
3808
  React.createElement(RouterContent$1, null, children)));
3796
3809
  };
3797
3810
 
@@ -3829,7 +3842,7 @@ const RouterContent = ({ children }) => {
3829
3842
  return React.createElement(IonRouter, { registerHistoryListener: registerHistoryListener }, children);
3830
3843
  };
3831
3844
  const IonReactHashRouter = ({ children, ...routerProps }) => {
3832
- return (React.createElement(HashRouter, { ...routerProps },
3845
+ return (React.createElement(HashRouter, { ...withTransitionDefaults(routerProps) },
3833
3846
  React.createElement(RouterContent, null, children)));
3834
3847
  };
3835
3848