0
0
Remixframework~20 mins

Nested routes and layouts in Remix - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Routes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered output of nested routes with layouts?

Consider a Remix app with a root layout and a nested route dashboard. The root layout renders a header and an <Outlet />. The dashboard route renders a welcome message. What will the user see when visiting /dashboard?

Remix
/* Root layout component */
import { Outlet } from '@remix-run/react';

export default function Root() {
  return (
    <>
      <header>Site Header</header>
      <Outlet />
    </>
  );
}

/* dashboard.jsx */
export default function Dashboard() {
  return <main>Welcome to your dashboard</main>;
}
ANothing renders because <Outlet /> is missing in dashboard
B<main>Welcome to your dashboard</main>
C<header>Site Header</header>
D<header>Site Header</header><main>Welcome to your dashboard</main>
Attempts:
2 left
💡 Hint

Remember that <Outlet /> in the root layout renders nested routes.

lifecycle
intermediate
1:30remaining
When does a nested layout component re-render in Remix?

In Remix, if you have a nested layout route and a child route, under which condition will the nested layout component re-render?

AWhen the URL changes to a route outside its nested tree
BWhen the child route changes but the nested layout route stays the same
COnly when the nested layout route's own loader data changes
DNever re-renders once mounted
Attempts:
2 left
💡 Hint

Think about how React components re-render when their props or state change.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a nested layout route in Remix?

Choose the correct file structure and code snippet to create a nested layout route admin with a nested users route.

Aroutes/admin/index.jsx with <Outlet /> and routes/admin/users.jsx for users route
Broutes/admin.jsx with <Outlet /> and routes/admin.users.jsx for users route
Croutes/admin.jsx with <Outlet /> and routes/admin/users.jsx for users route
Droutes/admin.jsx without <Outlet /> and routes/users.jsx for users route
Attempts:
2 left
💡 Hint

Remember Remix uses file system routing with folders and index.jsx files.

🔧 Debug
advanced
2:00remaining
Why does the nested route content not render inside the layout?

Given this root layout code, the nested route content does not appear. What is the cause?

Remix
export default function Root() {
  return (
    <>
      <header>My Site</header>
      <div>Content here</div>
    </>
  );
}

// Nested route file exists and exports a component
AHeader component blocks nested route rendering
BNested route file name is incorrect
CMissing <Outlet /> component in the root layout to render nested routes
DNested route component has syntax errors
Attempts:
2 left
💡 Hint

Check how nested routes are rendered inside layouts.

state_output
expert
2:30remaining
What is the final rendered output with nested layouts and shared state?

In a Remix app, the root layout provides a context with a counter state. The nested profile route consumes and increments the counter on a button click. After clicking the button twice, what is the displayed counter value in the profile route?

Remix
import { createContext, useContext, useState } from 'react';
import { Outlet } from '@remix-run/react';

const CounterContext = createContext();

export function Root() {
  const [count, setCount] = useState(0);
  return (
    <CounterContext.Provider value={{ count, setCount }}>
      <header>App Header</header>
      <Outlet />
    </CounterContext.Provider>
  );
}

// profile.jsx
import { useContext } from 'react';
import { CounterContext } from './root';

export default function Profile() {
  const { count, setCount } = useContext(CounterContext);
  return (
    <main>
      <p>Counter: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </main>
  );
}
ACounter: 2
BCounter: 0
CCounter: 1
DError: Context is undefined
Attempts:
2 left
💡 Hint

Think about how React state updates and context work across nested components.