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 |...