📖 Scenario: You are building a simple website using Remix. You want to create different pages that users can visit by typing URLs in their browser.
🎯 Goal: Create basic routes in Remix by adding files in the app/routes folder. Each route will show a simple message on the page.
📋 What You'll Learn
Create a route file for the home page that shows 'Welcome to the Home Page!'
Create a route file for the about page that shows 'About Us'
Create a route file for the contact page that shows 'Contact Information'
Use Remix's default export function to return JSX for each route
💡 Why This Matters
🌍 Real World
Creating routes is how websites show different pages when users visit different URLs. Remix uses file-based routing to make this easy.
💼 Career
Understanding routing is essential for web developers to build multi-page applications and improve user navigation.
Progress0 / 4 steps
1
Create the Home Page Route
Create a file called app/routes/index.tsx. Inside it, write a default export function called Index that returns a <div> with the text 'Welcome to the Home Page!'.
Remix
Hint
Remember, the home page route in Remix is the index.tsx file inside app/routes.
2
Create the About Page Route
Create a file called app/routes/about.tsx. Inside it, write a default export function called About that returns a <div> with the text 'About Us'.
Remix
Hint
Each route is a separate file inside app/routes. The file name becomes the URL path.
3
Create the Contact Page Route
Create a file called app/routes/contact.tsx. Inside it, write a default export function called Contact that returns a <div> with the text 'Contact Information'.
Remix
Hint
Remember to name the function and file to match the route path.
4
Add Links to Navigate Between Routes
In the app/routes/index.tsx file, import Link from @remix-run/react. Inside the Index function, add three <Link> components that link to '/', '/about', and '/contact' with the texts 'Home', 'About', and 'Contact' respectively. Wrap them in a <nav> element above the welcome message.
Remix
Hint
Use the Link component from Remix to create navigation links.
Practice
(1/5)
1. In Remix, how do you create a new route that matches the URL path /about?
easy
A. Create a file named about.jsx inside the app/routes folder.
B. Add a function named about() in app/root.jsx.
C. Create a folder named about inside app/components.
D. Add a route entry in a routes configuration file.
Solution
Step 1: Understand Remix routing structure
Remix creates routes based on files inside the app/routes folder.
Step 2: Match file name to URL path
To create a route for /about, create about.jsx inside app/routes.
Final Answer:
Create a file named about.jsx inside the app/routes folder. -> Option A
Quick Check:
Route file name = URL path [OK]
Hint: Route files in app/routes match URL paths directly [OK]
Common Mistakes:
Trying to add routes in root.jsx instead of app/routes folder
Creating route files in app/components folder
Expecting a config file for routes
2. Which of the following is the correct way to define a dynamic route parameter for a user ID in Remix?
easy
A. Create a file named user-$id.jsx inside app/routes.
B. Create a file named user/[id].jsx inside app/routes.
C. Create a file named user/:id.jsx inside app/routes.
D. Create a file named user/{id}.jsx inside app/routes.
Solution
Step 1: Recall Remix dynamic route syntax
Remix uses square brackets [param] in file names to define dynamic route parts.
Step 2: Match dynamic user ID route
For a user ID parameter, the file should be named user/[id].jsx.
Final Answer:
Create a file named user/[id].jsx inside app/routes. -> Option B
Quick Check:
Dynamic route uses [param] syntax [OK]
Hint: Use square brackets [param] for dynamic route files [OK]
Common Mistakes:
Using $id or :id instead of [id]
Using curly braces {id} which is invalid
Placing dynamic routes outside app/routes
3. Given the file app/routes/blog/[slug].jsx exporting a React component that renders <h1>{params.slug}</h1>, what will be rendered when visiting /blog/hello-world?
medium
A. Nothing, route not found
B.
[slug]
C.
blog/hello-world
D.
hello-world
Solution
Step 1: Understand dynamic route parameter usage
The file [slug].jsx captures the URL part after /blog/ as slug.
Step 2: Rendered output for /blog/hello-world
The component renders <h1>{params.slug}</h1>, so params.slug is hello-world.
4. You created a file app/routes/profile.jsx but visiting /profile shows a 404 error. What is the most likely cause?
medium
A. The file does not export a React component as default.
B. The file name should be profile.js instead of profile.jsx.
C. You need to add a route entry in a config file.
D. The route path should be /profiles to match the file.
Solution
Step 1: Check route file export requirements
Remix requires route files to export a React component as the default export.
Step 2: Identify cause of 404 error
If the file exists but does not export a default React component, Remix treats it as no route, causing 404.
Final Answer:
The file does not export a React component as default. -> Option A
Quick Check:
Default export React component required [OK]
Hint: Always export a default React component in route files [OK]
Common Mistakes:
Using named exports only without default export
Wrong file extension causing import issues
Expecting config file for routes
5. You want to create nested routes for a blog: /blog shows a list, and /blog/[postId] shows a post detail. How should you organize files in app/routes?
hard
A. Create blog.jsx and blog/[postId].jsx inside app/routes.
B. Create blog/index.jsx and blog-postId.jsx inside app/routes.
C. Create a folder blog with index.jsx and [postId].jsx inside it.
D. Create blog-list.jsx and blog-post.jsx inside app/routes.
Solution
Step 1: Understand nested route folder structure
Remix supports nested routes by creating folders with an index.jsx file for the base path.
Step 2: Organize blog routes
Put index.jsx inside blog folder for /blog, and [postId].jsx for dynamic post detail.
Final Answer:
Create a folder blog with index.jsx and [postId].jsx inside it. -> Option C
Quick Check:
Nested routes use folders with index.jsx [OK]
Hint: Use folder with index.jsx for base route, dynamic files for params [OK]
Common Mistakes:
Placing all files flat without folders for nested routes
Using dash instead of brackets for dynamic routes
Naming files incorrectly for nested paths
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.