0
0
NextJSframework~20 mins

Why file-based routing simplifies navigation in NextJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File-Based Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does Next.js file-based routing map URLs?
In Next.js, how does the file structure inside the app directory relate to the URLs users visit?
AFiles inside <code>app</code> need manual URL mapping in a config file to create routes.
BEach file or folder inside <code>app</code> automatically becomes a URL path segment matching its name.
COnly files named <code>index.js</code> inside <code>app</code> are accessible as URLs.
DNext.js ignores the <code>app</code> folder for routing and uses a separate <code>routes.js</code> file.
Attempts:
2 left
💡 Hint
Think about how folder names become parts of the website address.
component_behavior
intermediate
2:00remaining
What happens when you add a new folder in Next.js app?
If you add a new folder named blog inside the app directory with a page file inside, what URL will Next.js serve for that page?
AThe page will be served at the root URL <code>/</code> ignoring the folder.
BYou must update a routing config to make <code>/blog</code> work.
CNext.js will throw an error because nested folders are not allowed.
DThe page will be served at <code>/blog</code> automatically.
Attempts:
2 left
💡 Hint
Remember how folder names become URL parts.
📝 Syntax
advanced
2:00remaining
Identify the correct file structure for nested routes
Which folder and file structure correctly creates the nested URL /products/shoes in Next.js?
A<code>app/products/shoes/page.js</code>
B<code>app/products/shoes.js</code>
C<code>app/products-shoes/page.js</code>
D<code>app/products_shoes/page.js</code>
Attempts:
2 left
💡 Hint
Folders create URL segments, files named page.js define pages.
🔧 Debug
advanced
2:00remaining
Why does this Next.js route not work as expected?
Given this folder structure:
app/blog/page.js
and inside page.js you export a React component.
Why might navigating to /blog show a 404 error?
ANext.js requires a <code>route.js</code> file inside <code>blog</code> for routing.
BThe folder <code>blog</code> must be named <code>blogs</code> to work.
CThe <code>page.js</code> file is missing the default export of a React component.
DThe <code>app</code> folder must be renamed to <code>pages</code> for routing.
Attempts:
2 left
💡 Hint
Check the component export inside the page file.
state_output
expert
2:00remaining
What is the rendered output of this Next.js page component?
Consider this Next.js page component inside app/home/page.js:
export default function HomePage() {
  return (
    <main>
      <h1>Welcome</h1>
      <p>You are at /home</p>
    </main>
  )
}

What will a user see when visiting /home?
AA page with a heading 'Welcome' and a paragraph 'You are at /home'.
BA blank page because the component is missing a return statement.
CAn error because JSX tags are not allowed in Next.js page components.
DA page showing only the text '/home' without any heading.
Attempts:
2 left
💡 Hint
Look at the JSX returned by the component.