The specific case is that I use one page filter.jsx
to get the request from the user like the subject, the grade of student, the difficulty level, … Then I process them via an API filter/route.js
to filter the question database and send the filtered data back to the page filter.jsx
.
How can I create a button in filter.jsx
that when clicked will move to other page test.jsx
and use the filtered data in this test.jsx
page?
I used Link and router.push but they dont work. Maybe I was using it the wrong way.
2
Answers
There are a number of ways you could do this. One would be to use URL parameters in the
<Link>
from thefilter.jsx
page totest.jsx
, likeThen you can get this in the
test.jsx
page viaNext 14:
https://nextjs.org/docs/app/api-reference/functions/use-search-params
Next 13:
https://nextjs.org/docs/app/api-reference/file-conventions/page#searchparams-optional
Probably your filter value is in state so that when your API call resolves, you set the state and it updates the href in your
Link
, but you probably knew that already 🙂You can acheave this using two methods:
1. URL Parameters or Query Strings.
In Filter.jsx:
Test.jsx:
2. Next.js API Routes for Server-Side Data Fetching.
In filter.jsx:
Test.jsx: