0
0
Reactframework~20 mins

Client-side routing concept in React - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Client-side Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you click a in React Router?
Consider a React app using React Router. When you click a component, what is the main behavior that happens?
React
<Link to="/about">About</Link>
AReact Router intercepts the click and updates the URL without reloading the page, rendering the new component.
BThe browser reloads the entire page and navigates to /about.
CThe app throws an error because <Link> is not a valid HTML tag.
DThe URL changes but the page content does not update.
Attempts:
2 left
💡 Hint
Think about how single-page apps avoid full page reloads.
📝 Syntax
intermediate
2:00remaining
Identify the correct way to define a route in React Router v6
Which of the following is the correct syntax to define a route that renders at path '/'?
A<Route path="/" element={<HomePage />} />
B<Route path="/" children={<HomePage />} />
C<Route path="/" render={() => <HomePage />} />
D<Route path="/" component={HomePage} />
Attempts:
2 left
💡 Hint
React Router v6 uses a new prop to specify what to render.
state_output
advanced
2:00remaining
What is the URL and rendered output after navigating programmatically?
Given this React Router code snippet, what will be the URL and rendered output after the button is clicked?
React
import { useNavigate, Routes, Route } from 'react-router-dom';

function App() {
  const navigate = useNavigate();
  return (
    <>
      <button onClick={() => navigate('/dashboard')}>Go Dashboard</button>
      <Routes>
        <Route path="/" element={<h1>Home</h1>} />
        <Route path="/dashboard" element={<h1>Dashboard</h1>} />
      </Routes>
    </>
  );
}
AClicking the button causes a full page reload to '/dashboard'.
BURL stays '/' but the page shows 'Dashboard'.
CURL changes to '/dashboard' and the page shows 'Dashboard'.
DURL changes to '/dashboard' but the page still shows 'Home'.
Attempts:
2 left
💡 Hint
useNavigate changes the URL and triggers route rendering.
🔧 Debug
advanced
2:00remaining
Why does the route not render the component on URL change?
A developer wrote this React Router setup but the component does not render when the URL changes. What is the likely cause?
React
import { BrowserRouter, Routes, Route } from 'react-router-dom';

function App() {
  return (
    <BrowserRouter>
      <Route path="/about" element={<About />} />
    </BrowserRouter>
  );
}
AThe About component is not imported, causing a silent failure.
BThe path '/about' is invalid and must be '/about/'.
CBrowserRouter must be replaced with HashRouter for routing to work.
DRoutes component is missing around Route, so routing does not work.
Attempts:
2 left
💡 Hint
Check the required parent components for Route in React Router v6.
🧠 Conceptual
expert
3:00remaining
Why use client-side routing instead of server-side routing in React apps?
Which of the following best explains the main advantage of client-side routing in React apps?
AClient-side routing requires no JavaScript, so it works even if scripts are disabled.
BClient-side routing allows the app to update the URL and content without full page reloads, making navigation faster and smoother.
CClient-side routing automatically improves SEO by sending all routes to search engines.
DClient-side routing forces the browser to reload the entire page on every navigation.
Attempts:
2 left
💡 Hint
Think about user experience and speed when clicking links in single-page apps.