Using query parameters
A query parameter is part of the URL that allows additional parameters to be passed into a path. For example, /search?criteria=typescript
has a query parameter called criteria
with a value of typescript
. Query parameters are sometimes referred to as a search parameter.
In this section, we are going to implement a query parameter on the search page called criteria
, which will drive the search. We'll implement the search page along the way. Let's carry out the following steps to do this:
- We are going to start in
QuestionsData.ts
by creating a function to simulate a search via a web request:export const searchQuestions = async ( Â Â criteria: string, ): Promise<QuestionData[]> => { Â Â await wait(500); Â Â return questions.filter( Â Â Â Â q => Â Â Â Â Â Â q.title.toLowerCase() Â Â Â Â Â Â Â Â .indexOf(criteria.toLowerCase()) >= 0 |...