Using route parameters
In this section, we are going to define a Route
component for navigating to the question page. This will contain a variable called questionId
at the end of the path, so we will need to use what is called a route parameter. We'll implement more of the question page content in this section as well.
Adding the question page route
Let's carry out the following steps to add the question page route:
- In
App.tsx
, import theQuestionPage
component we created earlier in this chapter:import { QuestionPage } from './QuestionPage';
- In the
App
component's JSX, add aRoute
component for navigation to the question page inside theRoutes
component just above the wildcard route:<Routes> … <Route path="questions/:questionId" element={<QuestionPage />} /> <Route path="*" element={<NotFoundPage/>} /> </Routes>
Note that...