Script Valley
React.js: Complete Course
React Router and Navigation/Assessment

Practice & Assessment

Test your understanding of React Router and Navigation

Multiple Choice Questions

5
1

What is the purpose of the `<Outlet />` component in React Router v6?

2

How do you read a URL parameter like `/users/:userId` in a component?

3

What does `<Navigate replace />` do differently than `<Navigate />` alone?

4

What must wrap a React.lazy() imported component to handle loading states?

5

What is the key advantage of using React Router's loader function over useEffect for data fetching?

Coding Challenges

1
1

Blog with Nested Routes

Build a blog app with React Router v6. Routes: / (home, list of 5 hardcoded posts), /posts/:postId (single post detail, use useParams to display the matched post), /about (static page), * (404 not found page). Create a persistent Navbar with NavLink components. The post list page should link each post to its detail page. Implement a ProtectedRoute that blocks /admin route and redirects to /login. Use useNavigate on the login page to redirect back after 'logging in' (simulate with a button). Estimated time: 30 minutes.

Medium

Mini Project

1

E-commerce Product Browser SPA

Build a multi-page product browser. Routes: / (grid of products fetched from https://fakestoreapi.com/products), /products/:id (product detail with image, price, and description), /cart (protected route showing cart items), /login (login simulation). Implement: lazy loading for all route components with Suspense, a CartContext tracking added items, protected /cart route redirecting to /login with state, NavLink active styling, and 404 catch-all. Persist cart to localStorage using a custom hook.

Hard
Practice & Assessment โ€” React Router and Navigation โ€” React.js: Complete Course โ€” Script Valley โ€” Script Valley