📖 Scenario: You are building a simple website using Remix Framework. Each page (route) should have its own CSS file to keep styles organized and only load the styles needed for that page.
🎯 Goal: Create two routes, index and about, each with its own CSS file. Import the CSS files correctly so that each route loads only its own styles.
📋 What You'll Learn
Create a CSS file named index.css with a background color style
Create a CSS file named about.css with a different background color style
Create a route file index.jsx that imports index.css
Create a route file about.jsx that imports about.css
💡 Why This Matters
🌍 Real World
Websites often have multiple pages with different styles. Loading only the CSS needed for each page keeps the site fast and organized.
💼 Career
Front-end developers use route-based CSS imports to optimize styling and performance in modern web frameworks like Remix.
Progress0 / 4 steps
1
Create index.css with background color
Create a CSS file named index.css with a body selector that sets the background color to #e0f7fa.
Remix
Hint
Use the body selector and set background-color to #e0f7fa.
2
Create about.css with background color
Create a CSS file named about.css with a body selector that sets the background color to #fff3e0.
Remix
Hint
Use the body selector and set background-color to #fff3e0.
3
Create index.jsx route importing index.css
Create a React component in index.jsx that imports index.css using import "./index.css"; and exports a default function Index returning a <main> with text Home Page.
Remix
Hint
Use import "./index.css"; and create a function Index that returns <main>Home Page</main>.
4
Create about.jsx route importing about.css
Create a React component in about.jsx that imports about.css using import "./about.css"; and exports a default function About returning a <main> with text About Page.
Remix
Hint
Use import "./about.css"; and create a function About that returns <main>About Page</main>.
Practice
(1/5)
1. In Remix, how do you add CSS styles that apply only to a specific route?
easy
A. By exporting a links function that returns CSS links from the route file
B. By importing CSS files directly inside the component's JSX
C. By adding CSS inside a global stylesheet only
D. By using inline styles on every HTML element
Solution
Step 1: Understand Remix route styling
Remix uses a special links export in route files to load CSS only for that route.
Step 2: Why links is preferred
This method keeps styles scoped and improves loading by only fetching needed CSS.
Final Answer:
By exporting a links function that returns CSS links from the route file -> Option A
Quick Check:
Route CSS = links export [OK]
Hint: Use links export in route files for CSS [OK]
Common Mistakes:
Importing CSS inside JSX instead of using links
Adding all CSS globally instead of per route
Using inline styles everywhere
2. Which of the following is the correct syntax to import a CSS file in a Remix route using the links function?
D. export function links() { return { rel: 'stylesheet', href: './styles.css' }; }
Solution
Step 1: Identify correct links export syntax
Remix expects links as a function returning an array of objects with rel and href.
Step 2: Check arrow function usage
export const links = () => [{ rel: 'stylesheet', href: './styles.css' }]; uses an arrow function returning the correct array format, which is valid and common.