diff --git a/example/src/App.tsx b/example/src/App.tsx index 1225d3a..4d36312 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -28,7 +28,7 @@ function Routes() { animation, gestureDirection: "horizontal" }, - initialPath: '.', + initialPathname: '.', basePath: '/(react-motion-router/)?', disableBrowserRouting: isPWA() && isIOS(), }}> diff --git a/example/src/Screens/Overlays/index.tsx b/example/src/Screens/Overlays/index.tsx index c687968..1300236 100644 --- a/example/src/Screens/Overlays/index.tsx +++ b/example/src/Screens/Overlays/index.tsx @@ -34,7 +34,7 @@ export default function Overlays(props: OverlaysProps) {
{ } +interface SlidesProps extends ScreenComponentProps<{ hero: string; }> { } const KeyboardSwipeableViews = bindKeyboard(SwipeableViews); let isFirstLoad = false; export default function Slides(props: SlidesProps) { - const [index, setIndex] = useState(props.route.params.hero); + const [index, setIndex] = useState(Number(props.route.params.hero)); let y = 0; const onSwipeStart = (e: SwipeStartEvent) => { diff --git a/packages/core/src/RouterBase.tsx b/packages/core/src/RouterBase.tsx index e215a6e..968cc92 100644 --- a/packages/core/src/RouterBase.tsx +++ b/packages/core/src/RouterBase.tsx @@ -4,7 +4,6 @@ import { ScreenChild, RouterBaseEventMap, RouterHTMLElement, - ScreenState } from './common/types'; import { NestedRouterContext, RouterContext } from './RouterContext'; import { dispatchEvent, matchRoute, resolveBaseURLFromPattern } from './common/utils'; @@ -69,18 +68,23 @@ export abstract class RouterBase

{ - let router: RouterBase = this; + const activeRouters = [...this.#activeRoutersIter()]; // travel down router tree to find a router that can intercept - while (router?.child) { - if (router.child.canIntercept(e)) - router = router.child; - } - if (router.canIntercept(e)) { - router.intercept(e); + const interceptor = activeRouters.findLast(router => router.canIntercept(e)); + if (interceptor) { + interceptor.intercept(e); this.hasUAVisualTransition = e.hasUAVisualTransition; } } + *#activeRoutersIter() { + let router: RouterBase | null = this; + while (router) { + yield router; + router = router.child; + } + } + getRouterById(routerId: string, target?: RouterBase): RouterBase | null { const router = target ?? RouterBase.rootRouterRef?.deref(); if (router!.id === routerId) { @@ -166,7 +170,14 @@ export abstract class RouterBase

return new Promise((resolve, reject) => startTransition(() => { this.setState({ screenStack, fromKey, transition, destinationKey }, async () => { - const { initialPath } = this.props.config ?? {}; + const { initialPathname } = this.props.config ?? {}; const [firstEntry] = entries; if ( - initialPath + initialPathname && entries.length === 1 && firstEntry.url && !matchRoute( - initialPath, + initialPathname, firstEntry.url.pathname, this.baseURLPattern.pathname ) ) { const transitionFinished = window.navigation.transition?.finished ?? Promise.resolve(); transitionFinished.then(() => { - this.navigation.replace(initialPath).finished.then(() => { + this.navigation.replace(initialPathname).finished.then(() => { const state = e.destination.getState() as HistoryEntryState ?? {}; this.navigation.push(e.destination.url, state); });