fix: pagination in 'my likes' page redirecting to index page
This commit is contained in:
parent
745a2e0c54
commit
42b7911d6e
1 changed files with 11 additions and 7 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useSearchParams } from "next/navigation";
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
import { useMemo } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import { Icon } from "@iconify/react";
|
import { Icon } from "@iconify/react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -11,14 +11,18 @@ interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Pagination({ lastPage }: Props) {
|
export default function Pagination({ lastPage }: Props) {
|
||||||
|
const pathname = usePathname();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const page = Number(searchParams.get("page") ?? 1);
|
const page = Number(searchParams.get("page") ?? 1);
|
||||||
|
|
||||||
const createPageUrl = (pageNumber: number) => {
|
const createPageUrl = useCallback(
|
||||||
const params = new URLSearchParams(searchParams);
|
(pageNumber: number) => {
|
||||||
params.set("page", pageNumber.toString());
|
const params = new URLSearchParams(searchParams);
|
||||||
return `/?${params.toString()}`;
|
params.set("page", pageNumber.toString());
|
||||||
};
|
return `${pathname}?${params.toString()}`;
|
||||||
|
},
|
||||||
|
[searchParams, pathname]
|
||||||
|
);
|
||||||
|
|
||||||
const numbers = useMemo(() => {
|
const numbers = useMemo(() => {
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue