next/navigator revalidate path on /search?... (appDir)
Answered
Encyrtid wasp posted this in #help-forum
Encyrtid waspOP
Hi all, out hope all is good... I need some help to figure how
I'm using Nextjs 13 appDir and don't quite get how to do that
Modal Component code:
search/page.jsx Code:
Does anyone have any idea 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?13 Replies
just set dynamic to force-dynamic
you dont want to cache search anyhow
@Encyrtid wasp 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:
js
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:
js
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?
i have similar code and it works perfectly fine https://github.com/joulev/debug/tree/search-in-rsc-with-search-params
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 keyAnswer
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