import { PageLoad} from './PageLoad'
import { useLocation } from "react-router-dom";
const Pagination = (props) => {
const location = useLocation();
const { currentPage, setPage, totalPages } = props.pageControl;
useEffect(() => {
PageLoad(location.pathname);
}, [currentPage]);
}
// function in different js
const PageLoad= (URL) => {
console.log(URL);
}
// parent component
const [paginationValues, paginationApi] = usePagination();
const { currentPage, totalPages } = paginationValues;
const { setCurrentPage, setTotalPages } = paginationApi;
const pageControl = {
currentPage,
setPage: setCurrentPage,
totalPages,
tileBuffer: 5
};
当我更改分页时,我需要页面的当前URL,当组件加载时,我可以正确获取URL。例如:my-lists.html?page=1当我将分页更改为第二页时,URL是my-lists.html?page=2,但在控制台中,即使我的当前URL是my-lists. html?page=2,我仍然可以获取my-lists. html?page=1。
1条答案
按热度按时间qlzsbp2j1#