Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page active link working immediately after clicking before redirecting to that page how to solve this #487

Open
Sayem-Mahmud opened this issue May 15, 2023 · 0 comments

Comments

@Sayem-Mahmud
Copy link

Sayem-Mahmud commented May 15, 2023

page active link working immediately after clicking before redirecting to that page how to solve this

here is my component code:
import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { controller } from '../../../../../src/state/StateController';
import BigSourceCodeCard from './BigSourceCodeCard/BigSourceCodeCard';
import ReactPaginate from 'react-paginate';
import { ApkData } from '../../../../../interfaces/models';
import Loader from '../../../../helpers/Loader/Loader';
import { useRouter } from 'next/router';

interface Props {
apk: Array;
}

const LeftLayout: React.FC = ({ apk }) => {
const router=useRouter()
const states = useSelector(() => controller.states);
const [activePage, setActivePage] = useState(1);
// const {page}=router.query

const pageCount = Math.ceil(states.totalApk / states.itemsPerPage);

const handlePageClick = (event: any) => {
const selectedPage = event.selected + 1;
console.log('state',states.currentPage)
setActivePage(states.currentPage);

const url = window.location.href;

if (url.includes('search')) {
  window.location.href = `/page/${selectedPage}/search/${states.searchValue}`;
} else if (url.includes('category') && !url.includes('subcat')) {
  window.location.href = `/page/${selectedPage}/category/${states.categoryValue}`;
} else if (url.includes('subcat') && url.includes('category')) {
  window.location.href = `/page/${selectedPage}/category/${states.categoryValue}/subcat/${states.categorySubValue}`;
} else {
  window.location.href = `/page/${selectedPage}`;
}
};

return (
<>
{apk ? (
<>


{apk.map(item => {
return (
<React.Fragment>

</React.Fragment>
);
})}


<ReactPaginate
breakLabel='...'
breakLinkClassName={'pageNumber'}
pageRangeDisplayed={2}
marginPagesDisplayed={1}
renderOnZeroPageCount={null}
onPageChange={handlePageClick}
pageCount={pageCount}
previousLabel={'Prev'}
nextLabel={'Next'}
containerClassName={'paginationContainer'}
pageLinkClassName={'pageNumber'}
previousLinkClassName={'pageNumber'}
nextLinkClassName={'pageNumber'}
activeLinkClassName={'active'}
disabledLinkClassName={'disable'}
forcePage={activePage-1} // Remove this line
/>

</>
) : (



)}
</>
);
};

export default LeftLayout;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant