page-transition 0.2.0 → 0.2.1
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/README.md +1 -1
- package/dist/context/ActiveLinkContext.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ A page transition library for the Next.js App Router.
|
|
|
10
10
|
- Scroll restoration
|
|
11
11
|
|
|
12
12
|
## Install
|
|
13
|
-
  
|
|
14
14
|
|
|
15
15
|
`npm install page-transition`
|
|
16
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useRef } from "react";
|
|
3
|
+
import { createContext, useContext, useEffect, useRef, } from "react";
|
|
4
4
|
const ActiveLinkContext = createContext(null);
|
|
5
5
|
export function useActiveLinkContext() {
|
|
6
6
|
const context = useContext(ActiveLinkContext);
|
|
@@ -21,6 +21,9 @@ export function ActiveLinkProvider({ children }) {
|
|
|
21
21
|
if (ref) {
|
|
22
22
|
element = ref;
|
|
23
23
|
map.current.set(ref, href);
|
|
24
|
+
for (const [el, href] of map.current) {
|
|
25
|
+
el.classList.toggle('active', href === pathname);
|
|
26
|
+
}
|
|
24
27
|
}
|
|
25
28
|
if (!ref)
|
|
26
29
|
map.current.delete(element);
|
|
@@ -32,9 +35,6 @@ export function ActiveLinkProvider({ children }) {
|
|
|
32
35
|
el.classList.toggle('active', href === e.detail);
|
|
33
36
|
}
|
|
34
37
|
};
|
|
35
|
-
for (const [el, href] of map.current) {
|
|
36
|
-
el.classList.toggle('active', href === pathname);
|
|
37
|
-
}
|
|
38
38
|
window.addEventListener('nextPathname', handleActiveLink);
|
|
39
39
|
return () => {
|
|
40
40
|
window.removeEventListener('nextPathname', handleActiveLink);
|