logoReact Page Tracker|Demo Home
Even-numbered links will include a query string.
above buttons sample code
'use client';
import React from 'react';
import { usePageTrackerStore } from '../../../../src';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';

const BackForwardButtons = ({
  className,
  children,
  ...props
}: React.HTMLAttributes<HTMLDivElement>) => {
  const { isFirstPage, isLastPage, pageHistory, pageHistoryLength } = usePageTrackerStore(
    (state) => state,
  );
  return (
    <div className={cn('flex flex-col gap-3', className)} {...props}>
      <div className="flex gap-3">
        <Button variant="outline" disabled={pageHistory.length < 3} onClick={() => history.go(-2)}>
          ⏪️ (history.go(-2)
        </Button>
        <Button variant="outline" disabled={isFirstPage} onClick={() => history.back()}>
          ◀️ (history.back)
        </Button>
        <Button variant="outline" disabled={isLastPage} onClick={() => history.forward()}>
          ️▶️ (history.forward)
        </Button>
        <Button
          variant="outline"
          disabled={pageHistoryLength - pageHistory.length < 2 || isLastPage}
          onClick={() => history.go(2)}
        >
          ⏩️ (history.go(2)
        </Button>
      </div>
      {/* The following `children` is for RSC to render code */}
      {children}
    </div>
  );
};

export default BackForwardButtons;

Demo 9

👆Try clicking the browser's back and forward buttons and checking following values!

{"pageIndex": 0,"referrer": "","pageEvent": undefined,"isFirstPage": true,"isLastPage": true,"pageHistory": [],"pageHistoryLength": 0,}