page-transition 0.1.0-beta.17 → 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;
|
|
@@ -110,9 +113,8 @@ export function CssTransitionProvider({ header, options, children }) {
|
|
|
110
113
|
state.current = 'entering';
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
|
-
console.log('pathname fired', pathname, 'state:' + state.current);
|
|
114
116
|
if (state.current === 'navigating')
|
|
115
|
-
currentPathname.current = pathname;
|
|
117
|
+
currentPathname.current = window.location.pathname;
|
|
116
118
|
reverse.current.lock = false;
|
|
117
119
|
}, [pathname]);
|
|
118
120
|
const value = useMemo(() => ({ handleLinkClick, overlayWrapper, overlayItems }), []);
|
|
@@ -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({
|
|
@@ -43,8 +43,6 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
43
43
|
const pop = useTransitionEndObj({
|
|
44
44
|
transitionEndData,
|
|
45
45
|
fn: () => {
|
|
46
|
-
console.log('pop transitionEnd called');
|
|
47
|
-
console.log(checkTransitionFinish(transitionEndData.current, () => { }));
|
|
48
46
|
state.current = 'navigating';
|
|
49
47
|
window.scrollTo(0, window.history.state.scrollY ?? 0);
|
|
50
48
|
resolveFn.current?.();
|
|
@@ -60,9 +58,7 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
60
58
|
resolveUseFn.current = reject;
|
|
61
59
|
new Promise((resolveNavigating) => {
|
|
62
60
|
if (state.current === "navigating") {
|
|
63
|
-
console.log('state.current === "navigating"');
|
|
64
61
|
if (currentPathname.current !== window.location.pathname) {
|
|
65
|
-
console.log('currentPathname.current !== window.location.pathname');
|
|
66
62
|
if (checkTransitionFinish(transitionEndData.current, () => {
|
|
67
63
|
resolveFn.current?.();
|
|
68
64
|
setPromise(null);
|
|
@@ -70,7 +66,6 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
70
66
|
return;
|
|
71
67
|
}
|
|
72
68
|
else if (currentPathname.current === window.location.pathname) {
|
|
73
|
-
console.log('currentPathname.current === window.location.pathname');
|
|
74
69
|
if (checkTransitionFinish(transitionEndData.current, afterExitFn.current)) {
|
|
75
70
|
return;
|
|
76
71
|
}
|
|
@@ -80,15 +75,10 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
80
75
|
}
|
|
81
76
|
}
|
|
82
77
|
else {
|
|
83
|
-
console.log('not navigating');
|
|
84
78
|
resolveNavigating();
|
|
85
79
|
}
|
|
86
80
|
}).then(() => {
|
|
87
|
-
console.log('after resolveNavigating', 'state:', state.current);
|
|
88
|
-
console.log('after resolveNavigating', 'currentPathname.current:', currentPathname.current);
|
|
89
|
-
console.log('window.location.pathname:', window.location.pathname);
|
|
90
81
|
if (currentPathname.current === window.location.pathname) {
|
|
91
|
-
console.log('currentPathname.current === window.location.pathname');
|
|
92
82
|
transitionEnd({
|
|
93
83
|
transitionEndObj: afterExit,
|
|
94
84
|
transitionEndHandler,
|
|
@@ -103,8 +93,6 @@ export function usePopState({ container, currentPathname, transitionEndData, tra
|
|
|
103
93
|
reverse,
|
|
104
94
|
delay
|
|
105
95
|
});
|
|
106
|
-
console.log('transitionEnd called Pop');
|
|
107
|
-
console.log(checkTransitionFinish(transitionEndData.current, () => { }));
|
|
108
96
|
container.current?.classList.remove('enter');
|
|
109
97
|
container.current?.classList.add('exit');
|
|
110
98
|
state.current = 'exiting';
|