Skip to content

Commit

Permalink
Add comment explaining resolvedUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcohen committed Oct 2, 2023
1 parent a2a4c6b commit 931b3b4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pages/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export default function Search({ results }) {
)
}

/**
* resolvedUrl is the original URL of the search page including the search query parameters.
* It is provided by Next.js as an attribute of the context object that is passed to getServerSideProps.
*
* Here it is used to construct a SearchParams object from the parsed query parameters in order to fetch the
* relevant search results on the server side (via fetchResults).
*
*/
export async function getServerSideProps({ resolvedUrl }) {
// Remove everything before the query string delineator '?', necessary for correctly parsing the 'q' param.
const queryString = resolvedUrl.slice(resolvedUrl.indexOf("?") + 1)
Expand Down

0 comments on commit 931b3b4

Please sign in to comment.