02 / 14

Implement declarative mode to implement router?

Routes are configured by rendering <Routes> and <Route> that couple URL segments to UI elements.

javascript
Difficulty: 6/10
Topics: react-router, declarative routing, navigation state

Scenario Questions

0-2 years experience
  1. 1

    How would you set up a basic declarative router in a new React app using React Router v6?

  2. 2

    What happens if you place a <Route> component outside of a <Routes> wrapper?

  3. 3

    If you need to navigate to a different page after a button click, how can you keep the router declarative while still triggering the navigation?

2-5 years experience
  1. 1

    We have a modal that should open when the URL contains a specific query parameter; how would you implement that using declarative routing and what trade‑offs might you consider?

  2. 2

    A teammate renamed a route path from '/users/:id' to '/users/:userId' and the component stopped receiving the expected prop. How would you debug the issue?

  3. 3

    How would you protect certain routes based on authentication state using a declarative route tree, and what pitfalls should you watch out for?

5-8 years experience
  1. 1

    Our app receives thousands of routes from a CMS. How would you design a declarative routing solution that scales, supports lazy loading, and avoids bundle bloat?

  2. 2

    Describe how you would handle data fetching that must complete before a route renders, while keeping the router declarative. What edge cases need special handling?

  3. 3

    If the product must support both client‑side navigation and server‑side rendering, what changes are required in a declarative router setup?

8+ years experience
  1. 1

    We’re planning to migrate a legacy codebase that uses manual history pushes throughout the app to a declarative routing model. How would you approach the migration to minimize risk and coordinate across multiple teams?

  2. 2

    Discuss the long‑term maintenance implications of choosing a declarative router over a custom imperative solution in a large organization. What metrics would you track to evaluate its success?

  3. 3

    When evaluating third‑party routing libraries for a multi‑team product, how would you set criteria to decide between a declarative library and building an internal router?

Follow-up Questions

  • How would you test that your declarative routes behave as expected?
  • What performance metrics would you monitor after deploying the router?
  • If a route needs to be pre‑loaded based on a user role, how would you integrate that?