0
0
Reactframework~5 mins

Defining routes in React - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of defining routes in a React application?
Defining routes lets you decide which component to show when the user visits a specific URL. It helps create different pages or views in a single app.
Click to reveal answer
beginner
Which React library is commonly used for defining routes?
React Router is the most popular library to define routes in React apps. It helps manage navigation and URL changes easily.
Click to reveal answer
beginner
What does the <Route> component do in React Router?
The <Route> component tells React Router which component to show when the URL matches a path you specify.
Click to reveal answer
beginner
How do you define a route for the home page '/' in React Router?
You use <Route path='/' element={<Home />} /> inside a <Routes> component to show the Home component at the root URL.
Click to reveal answer
intermediate
Why do we wrap <Route> components inside a <Routes> component?
The <Routes> component groups all routes and ensures only the best matching route is shown. It manages route matching logic.
Click to reveal answer
Which component from React Router wraps all route definitions?
A<Switch>
B<Routes>
C<Route>
D<Router>
How do you specify which component to render for a route?
AUsing the 'render' prop
BUsing the 'component' prop
CUsing the 'element' prop
DUsing the 'view' prop
What happens if no route matches the current URL?
AA fallback or 'not found' route can be shown
BThe first route is shown
CNothing is rendered
DThe app crashes
Which hook lets you navigate programmatically in React Router?
AuseNavigate
BuseRoute
CuseHistory
DuseLocation
What is the correct way to import routing components in React Router v6?
Aimport { BrowserRouter, Switch, Route } from 'react-router-dom';
Bimport { Router, Switch, Route } from 'react-router-dom';
Cimport { Router, Routes, Route } from 'react-router-dom';
Dimport { BrowserRouter, Routes, Route } from 'react-router-dom';
Explain how to define a route for a 'Profile' page in React Router.
Think about wrapping routes and specifying the path and component.
You got /4 concepts.
    Describe why we use the component and how it affects route matching.
    Consider how React Router decides which page to show.
    You got /4 concepts.