supermemoryai / opensearch-ai

SearchGPT / Perplexity clone, but personalised for you.
https://opensearch-ai.pages.dev
944 stars 127 forks source link

Replace window.location.href with Next.js Navigation #22

Closed Arindam200 closed 3 months ago

Arindam200 commented 3 months ago

Description

Currently, the codebase uses window.location.href to navigate to the home page when a button is clicked. This approach is not optimal in a Next.js application, as it bypasses the client-side routing capabilities provided by Next.js. To improve the navigation and leverage the full potential of Next.js, we should replace the direct use of window.location.href with the Link component or useRouter from Next.js.

Current Code

{searchResultsData && (
  <button
    onClick={() => {
      window.location.href = "/";
    }}
  >
    Home
  </button>
)}

Proposed Solution

Replace the current implementation with either the Link component or the useRouter hook from Next.js.

Using Link Component

import Link from 'next/link';

{searchResultsData && (
  <Link href="/">
    <button>
      Home
    </button>
  </Link>
)}

Using useRouter Hook

import { useRouter } from 'next/router';

const Component = () => {
  const router = useRouter();

  return (
    {searchResultsData && (
      <button
        onClick={() => {
          router.push('/');
        }}
      >
        Home
      </button>
    )}
  );
};

Benefits

Additional Context

If there are other instances in the codebase where window.location.href is used for navigation, those should also be updated to use Next.js's navigation methods.

Note:

I would like to work on this

References