Bird
Raised Fist0
NextJSframework~20 mins

Multiple root layouts with route groups in NextJS - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Next.js Multiple Root Layouts Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What layout is applied to the /settings route?

Given this Next.js app structure using route groups and multiple root layouts:

app/(marketing)/layout.tsx
app/(marketing)/page.tsx
app/(dashboard)/layout.tsx
app/(dashboard)/settings/page.tsx
app/layout.tsx

Which layout component wraps the /settings page?

NextJS
/*
app/layout.tsx
export default function RootLayout({ children }) {
  return <html><body><div>Root Layout {children}</div></body></html>
}

app/(marketing)/layout.tsx
export default function MarketingLayout({ children }) {
  return <div>Marketing Layout {children}</div>
}

app/(dashboard)/layout.tsx
export default function DashboardLayout({ children }) {
  return <div>Dashboard Layout {children}</div>
}

app/(dashboard)/settings/page.tsx
export default function SettingsPage() {
  return <p>Settings Page</p>
}
*/
ARootLayout > DashboardLayout > SettingsPage
BRootLayout > MarketingLayout > DashboardLayout > SettingsPage
CDashboardLayout > SettingsPage
DRootLayout > MarketingLayout > SettingsPage
Attempts:
2 left
💡 Hint

Remember that route groups are folders in parentheses that help organize routes but do not add to the URL path. The root layout always wraps all pages.

📝 Syntax
intermediate
2:00remaining
Which code correctly defines a layout for a route group?

In Next.js App Router, how do you correctly export a layout component inside a route group folder (admin)?

Aexport default function AdminLayout({ children }) { return <html><body>{children}</body></html> }
Bexport default function AdminLayout({ children }) { return <div>{children}</div> }
Cexport default function AdminLayout() { return <html><body>{children}</body></html> }
Dexport default function AdminLayout({ children }) { return <html><head></head><body>{children}</body></html> }
Attempts:
2 left
💡 Hint

Layouts inside route groups must accept { children } as a prop and should not include <html> or <body> tags (those are only for the root layout).

🔧 Debug
advanced
2:00remaining
Why does the /profile page not use the (user) layout?

Given this folder structure:

app/layout.tsx
app/(user)/layout.tsx
app/(user)/profile/page.tsx
app/(admin)/layout.tsx
app/(admin)/dashboard/page.tsx

The /profile page renders only the root layout, not the (user) layout. What is the most likely cause?

AThe (user) folder is missing the layout.tsx file.
BThe (user) folder is named incorrectly and should not have parentheses.
CThe profile page is outside the (user) folder.
DThe (user) layout.tsx does not export a default React component.
Attempts:
2 left
💡 Hint

Check the export of the layout component inside the route group.

❓ state_output
advanced
2:00remaining
What is the rendered output for nested layouts with route groups?

Consider this Next.js app structure and components:

app/layout.tsx
export default function RootLayout({ children }) {
  return 
Root {children}
} app/(marketing)/layout.tsx export default function MarketingLayout({ children }) { return
Marketing {children}
} app/(marketing)/home/page.tsx export default function HomePage() { return

Welcome Home

}

What is the full rendered HTML output for the /home page?

A<html><body><div>Root <section>Marketing <p>Welcome Home</p></section></div></body></html>
B<html><body><section>Marketing <div>Root <p>Welcome Home</p></div></section></body></html>
C<div>Root <section>Marketing <p>Welcome Home</p></section></div>
D<html><body><div>Root <p>Welcome Home</p></div></body></html>
Attempts:
2 left
💡 Hint

Remember the root layout wraps everything, then nested layouts wrap their children.

🧠 Conceptual
expert
2:00remaining
How do route groups affect URL paths and layout nesting?

In Next.js App Router, what is the effect of using route groups (folders in parentheses) on URL paths and layout nesting?

ARoute groups add a segment to the URL path but do not affect layout nesting.
BRoute groups neither affect URL paths nor layout nesting; they are only for file organization.
CRoute groups do not add to the URL path but allow separate layout nesting for grouped routes.
DRoute groups add a segment to the URL path and also create separate layout nesting.
Attempts:
2 left
💡 Hint

Think about how parentheses in folder names affect routing and layouts.

Practice

(1/5)
1. What is the main purpose of using multiple root layouts in a Next.js app?
easy
A. To load all pages with the same layout
B. To change the URL structure automatically
C. To have different main designs for different parts of the app
D. To disable routing in some parts of the app

Solution

  1. Step 1: Understand root layouts

    Root layouts define the main design or structure for pages in a Next.js app.
  2. Step 2: Purpose of multiple root layouts

    Using multiple root layouts allows different parts of the app to have their own main design, improving organization and user experience.
  3. Final Answer:

    To have different main designs for different parts of the app -> Option C
  4. Quick Check:

    Multiple root layouts = different main designs [OK]
Hint: Multiple root layouts mean different main designs [OK]
Common Mistakes:
  • Thinking multiple root layouts change URLs
  • Assuming all pages share one layout
  • Believing layouts disable routing
2. Which folder name correctly creates a route group without changing the URL in Next.js?
easy
A. dashboard/(admin)/settings
B. dashboard/admin/settings
C. dashboard/[admin]/settings
D. dashboard/{admin}/settings

Solution

  1. Step 1: Identify route group syntax

    Route groups use parentheses in folder names to group routes without affecting URLs.
  2. Step 2: Check options

    Only dashboard/(admin)/settings uses parentheses correctly: (admin). Other options use brackets or braces which are for dynamic routes or invalid.
  3. Final Answer:

    dashboard/(admin)/settings -> Option A
  4. Quick Check:

    Route groups use parentheses ( ) [OK]
Hint: Route groups use ( ) in folder names [OK]
Common Mistakes:
  • Using square brackets [] for route groups
  • Using curly braces {} which are invalid
  • Confusing dynamic routes with route groups
3. Given this folder structure:
app/
  (marketing)/
    layout.js
    page.js
  (dashboard)/
    layout.js
    dashboard/page.js
What layout will the page at URL / use?
medium
A. Both layouts will be combined
B. The layout from (dashboard) folder
C. No layout will be applied
D. The layout from (marketing) folder

Solution

  1. Step 1: Understand route groups and root layouts

    Route groups like (marketing) and (dashboard) separate parts of the app with their own layouts.
  2. Step 2: Determine which route group matches URL '/'

    The root URL '/' matches the (marketing) group because it is the default or main group for the homepage.
  3. Final Answer:

    The layout from (marketing) folder -> Option D
  4. Quick Check:

    URL '/' uses (marketing) layout [OK]
Hint: Root URL uses main route group's layout [OK]
Common Mistakes:
  • Assuming dashboard layout applies to '/'
  • Thinking layouts combine automatically
  • Believing no layout applies by default
4. You created a route group folder named (admin) but your app shows a 404 error when visiting /admin. What is the likely mistake?
medium
A. You forgot to restart the Next.js server
B. Route group folders do not change URLs, so /admin URL does not exist
C. You must add a dynamic route file inside (admin) folder
D. Parentheses in folder names are invalid syntax

Solution

  1. Step 1: Understand route groups and URLs

    Route groups using parentheses group routes but do not add to the URL path.
  2. Step 2: Check URL vs folder name

    The folder (admin) does not create /admin URL. To have /admin URL, folder must be named 'admin' without parentheses.
  3. Final Answer:

    Route group folders do not change URLs, so /admin URL does not exist -> Option B
  4. Quick Check:

    Route groups don't add URL segments [OK]
Hint: Route groups don't add URL parts [OK]
Common Mistakes:
  • Thinking (admin) folder creates /admin URL
  • Believing parentheses are invalid
  • Assuming dynamic routes are needed here
5. You want to create two separate main layouts: one for public pages and one for user dashboard pages. You also want URLs like /login and /dashboard/profile. How should you organize your folders using multiple root layouts and route groups?
hard
A. Create app/(public)/layout.js and app/(dashboard)/layout.js, put pages inside each, and use route groups to keep URLs clean
B. Create app/public/layout.js and app/dashboard/layout.js folders without parentheses
C. Put all pages in app/layout.js and use conditional rendering inside layout
D. Use dynamic routes like app/[section]/layout.js to switch layouts

Solution

  1. Step 1: Use route groups for separate layouts

    Route groups with parentheses let you organize folders without affecting URLs, perfect for multiple root layouts.
  2. Step 2: Organize folders for public and dashboard

    Creating (public) and (dashboard) folders with their own layouts keeps code clean and URLs like /login and /dashboard/profile work as expected.
  3. Final Answer:

    Create app/(public)/layout.js and app/(dashboard)/layout.js, put pages inside each, and use route groups to keep URLs clean -> Option A
  4. Quick Check:

    Route groups + multiple root layouts = clean URLs and separate designs [OK]
Hint: Use ( ) folders for layouts without changing URLs [OK]
Common Mistakes:
  • Not using parentheses, causing URL changes
  • Putting all pages under one layout losing separation
  • Using dynamic routes incorrectly for layouts
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard