page-transition 0.1.0-beta.18 → 0.1.0-beta.19
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.
|
@@ -28,6 +28,7 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
28
28
|
initPathname: pathname
|
|
29
29
|
});
|
|
30
30
|
const state = useRef('idle');
|
|
31
|
+
const basePath = useRef(null);
|
|
31
32
|
const useUse = useRef(false);
|
|
32
33
|
const resolveUseFn = useRef(null);
|
|
33
34
|
const reverse = useRef({
|
|
@@ -73,7 +74,8 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
73
74
|
reverse,
|
|
74
75
|
delay,
|
|
75
76
|
useUse,
|
|
76
|
-
resolveUseFn
|
|
77
|
+
resolveUseFn,
|
|
78
|
+
basePath
|
|
77
79
|
});
|
|
78
80
|
useScrollRestoration();
|
|
79
81
|
const removeEnter = useTransitionEndObj({
|
|
@@ -87,6 +89,7 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
87
89
|
useEffect(() => {
|
|
88
90
|
if (mount.current.mounted === false &&
|
|
89
91
|
mount.current.initPathname === pathname) {
|
|
92
|
+
basePath.current = window.location.pathname.slice(0, -pathname.length);
|
|
90
93
|
return;
|
|
91
94
|
}
|
|
92
95
|
mount.current.mounted = true;
|
|
@@ -21,6 +21,7 @@ interface Props {
|
|
|
21
21
|
delay: RefObject<number | null>;
|
|
22
22
|
useUse: RefObject<boolean>;
|
|
23
23
|
resolveUseFn: RefObject<(() => void) | null>;
|
|
24
|
+
basePath: RefObject<string | null>;
|
|
24
25
|
}
|
|
25
|
-
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn }: Props): void;
|
|
26
|
+
export declare function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn, basePath }: Props): void;
|
|
26
27
|
export {};
|
|
@@ -4,7 +4,7 @@ import { useRouter } from "next/navigation";
|
|
|
4
4
|
import { useTransitionEndObj } from "../hooks/useTransitionEndObj";
|
|
5
5
|
import { transitionEnd } from "../functions/transitionEnd";
|
|
6
6
|
import { checkTransitionFinish } from "../functions/checkTransitionFinish";
|
|
7
|
-
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn }) {
|
|
7
|
+
export function useHandleLinkClick({ container, handleLinkClick, currentPathname, transitionEndData, transitionEndHandler, reverse, delay, state, useUse, resolveUseFn, basePath }) {
|
|
8
8
|
const router = useRouter();
|
|
9
9
|
const afterExitFn = useRef(null);
|
|
10
10
|
const nextPage = useRef(null);
|
|
@@ -51,13 +51,14 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
51
51
|
handleLinkClick.current = useCallback((e, url) => {
|
|
52
52
|
e.preventDefault();
|
|
53
53
|
nextPage.current = url;
|
|
54
|
+
const basePathUrl = basePath.current ? basePath.current + url : url;
|
|
54
55
|
new Promise((resolve) => {
|
|
55
56
|
if (state.current === 'navigating') {
|
|
56
57
|
console.log('state.current === navigating');
|
|
57
|
-
if (
|
|
58
|
+
if (basePathUrl === currentPathname.current) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
else if (
|
|
61
|
+
else if (basePathUrl !== currentPathname.current) {
|
|
61
62
|
if (checkTransitionFinish(transitionEndData.current, () => {
|
|
62
63
|
if (!nextPage.current)
|
|
63
64
|
return;
|
|
@@ -73,7 +74,7 @@ export function useHandleLinkClick({ container, handleLinkClick, currentPathname
|
|
|
73
74
|
resolve();
|
|
74
75
|
}
|
|
75
76
|
}).then(() => {
|
|
76
|
-
if (
|
|
77
|
+
if (basePathUrl === currentPathname.current) {
|
|
77
78
|
if (state.current !== 'exiting')
|
|
78
79
|
return;
|
|
79
80
|
transitionEnd({
|