Next.js Discord

Discord Forum

next/navigator revalidate path on /search?... (appDir)

Answered
Encyrtid wasp posted this in #help-forum
Open in Discord
Encyrtid waspOP
Hi all, out hope all is good... I need some help to figure how next/navigator works... What I'm trying to achieve is that every time I click on "Search" the Search page is "Revalidate"...

I'm using Nextjs 13 appDir and don't quite get how to do that

Modal Component code:
  const handleSearch = () => {
    const searchUrl = `/search?location=${search.location}&checkIn=${search.checkIn}&checkOut=${search.checkOut}&guests=${search.guests}&price_to=${search.priceTo}&price_from=${search.priceFrom}`;
    router.replace(searchUrl);
    closeModal();
  };


search/page.jsx Code:
async function getData(searchParams) {
  const queryParams = new URLSearchParams(searchParams).toString();
  let res = await fetch(`http://localhost:5500/search?${queryParams}`, {
    cache: "no-cache",
  });
  if (!res.ok) {
    return { data: { error: true } };
  }
  return res.json();
}

export default async function SearchPage({ searchParams }) {
  const data = await getData(searchParams);

  return (
    <div>
      <h1>Search Page</h1>
      <p>{JSON.stringify(data)}</p>
    </div>
  );
}


Does anyone have any idea how next/navigator can handle that?
Answered by joulev
you can trigger Suspense manually with key
View full answer

13 Replies

just set dynamic to force-dynamic
you dont want to cache search anyhow
Encyrtid waspOP
my servers are getting the request correctly, the problem here is that my page (search) is not getting into the loading state when the request is made
Encyrtid waspOP
yes, please
@Encyrtid wasp yes, please
you can trigger Suspense manually with key
Answer
basically this commit contains all the changes you need
Encyrtid waspOP
@joulev thank you so much for all your attention! It all looks great! thanks again for the effort to help! 😄
you're welcome