Challenge - 5 Problems
React Router Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the rendered output of this React Router setup?
Consider this React component using React Router. What will be displayed when the URL path is
/about?React
import { BrowserRouter, Routes, Route } from 'react-router-dom'; function App() { return ( <BrowserRouter> <Routes> <Route path='/' element={<h1>Home</h1>} /> <Route path='/about' element={<h1>About Us</h1>} /> <Route path='/contact' element={<h1>Contact</h1>} /> </Routes> </BrowserRouter> ); }
Attempts:
2 left
💡 Hint
Look at the path that matches the URL
/about.✗ Incorrect
The
Route with path /about matches the URL, so its element <h1>About Us</h1> is rendered.📝 Syntax
intermediate2:00remaining
Which option correctly defines a nested route in React Router?
You want to define a nested route where
/dashboard/settings renders a Settings component inside Dashboard. Which code snippet is correct?Attempts:
2 left
💡 Hint
Nested routes are defined by placing child
Route inside a parent Route.✗ Incorrect
Option A correctly nests the
settings route inside the dashboard route using child Route elements.🔧 Debug
advanced2:00remaining
Why does this route not render the expected component?
Given this code, navigating to
/profile shows a blank page. What is the cause?React
import { BrowserRouter, Routes, Route } from 'react-router-dom'; function App() { return ( <BrowserRouter> <Routes> <Route path='/profile' element={<Profile />} /> </Routes> </BrowserRouter> ); }
Attempts:
2 left
💡 Hint
Check the prop name used to specify the component to render in
Route.✗ Incorrect
React Router v6 uses
element prop with JSX element, not component prop.❓ state_output
advanced2:00remaining
What is the output when navigating between routes with state?
Consider this React Router code. What will be logged when navigating from
/home to /details with state { fromHome: true }?React
import { BrowserRouter, Routes, Route, useLocation } from 'react-router-dom'; function Details() { const location = useLocation(); console.log(location.state); return <h1>Details Page</h1>; } function App() { return ( <BrowserRouter> <Routes> <Route path='/home' element={<button onClick={() => window.history.pushState({ fromHome: true }, '', '/details')}>Go to Details</button>} /> <Route path='/details' element={<Details />} /> </Routes> </BrowserRouter> ); }
Attempts:
2 left
💡 Hint
React Router's
useLocation reads state passed via Link or navigate, not window.history.pushState.✗ Incorrect
Using
window.history.pushState does not update React Router's location state, so location.state is null.🧠 Conceptual
expert2:00remaining
Which statement about React Router route matching is true?
React Router v6 matches routes based on the URL path. Which of these statements is correct about how it matches routes?
Attempts:
2 left
💡 Hint
Think about how React Router v6 chooses which route to render when multiple routes could match.
✗ Incorrect
React Router v6 uses a ranking system to find the best match based on path specificity, not order.