Complete the code to import a component from the correct folder in an Astro project.
import Header from '../src/components/[1].astro';
The components folder usually contains components with PascalCase names matching the file names. So 'Header' matches 'Header.astro'.
Complete the code to define the main content area in an Astro page using the correct HTML semantic tag.
<[1]> <h1>Welcome to Astro</h1> </[1]>
The
Fix the error in the Astro page frontmatter by completing the export statement correctly.
--- export const [1] = 'My Astro Site'; ---
The frontmatter export should use 'title' in lowercase to match Astro conventions for page metadata.
Fill both blanks to create a dictionary comprehension that maps page names to their paths in Astro.
const pages = { [1]: `/pages/$[2].astro` };We use 'pageName' as the key and 'name' as the variable in the path string to dynamically build paths.
Fill all three blanks to create a reactive signal and update it on button click in Astro with client:load.
--- import { signal } from '@astrojs/signals'; const count = signal([1]); --- <button client:load onClick={() => count.value [2] [3]>Click me</button> <p>Count: {count.value}</p>
We start the signal at 0, then increment it by 1 on each click using '+=' operator.
Practice
Solution
Step 1: Understand folder roles in Astro
Thesrc/folder is where you put your source code like components, pages, and styles.Step 2: Identify the correct folder for code
Thepublic/folder is for static files like images, not code.Final Answer:
src/-> Option AQuick Check:
Source code folder =src/[OK]
src/, static files in public/ [OK]- Confusing
public/withsrc/ - Thinking
assets/is default code folder - Assuming
dist/holds source code
public/ folder inside an Astro component?Solution
Step 1: Understand how
Files inpublic/files are servedpublic/are served from the root URL, so you reference them with a leading slash.Step 2: Choose the correct path format
Using/images/photo.jpgcorrectly points topublic/images/photo.jpg.Final Answer:
<img src="/images/photo.jpg" /> -> Option CQuick Check:
Static files use root-relative paths [OK]
- Using relative paths like 'src/images' for public files
- Including 'public/' in the path
- Using relative paths that don't work in deployed site
project/ āā public/ ā āā logo.png āā src/ ā āā components/ ā āā Header.astro āā src/pages/index.astro
What will be the correct way to display
logo.png inside Header.astro?Solution
Step 1: Recall how
Files inpublic/files are servedpublic/are served from the root URL, so you use a root-relative path starting with '/'.Step 2: Apply correct path in component
Using/logo.pngcorrectly points to the image regardless of component location.Final Answer:
<img src="/logo.png" alt="Logo" /> -> Option DQuick Check:
Public files use root-relative paths [OK]
- Trying to use relative paths to
public/folder - Including 'public' in the path
- Using relative paths that break on deployment
Cannot find module './public/image.png'What is the likely cause based on Astro's project structure?
Solution
Step 1: Understand how static files are accessed
Static files inpublic/are not imported via relative paths in code; they are referenced by URL paths.Step 2: Identify the error cause
Trying to import a file frompublic/using a relative import causes this error.Final Answer:
Trying to import a static file frompublic/using a relative import -> Option BQuick Check:
Static files are referenced by URL, not imported [OK]
public/; use URL paths [OK]- Importing images or static files as modules
- Placing
public/insidesrc/ - Assuming
public/files are bundled like code
/about. Where should you place the new file in the project structure?Solution
Step 1: Understand Astro's page routing
Files insidesrc/pages/map directly to site URLs.Step 2: Choose correct location for new page
Placingabout.astroinsidesrc/pages/creates the/aboutroute.Final Answer:
src/pages/about.astro-> Option AQuick Check:
Pages go insrc/pages/folder [OK]
src/pages/ for routing [OK]- Placing pages in
src/components/ - Adding pages directly in
src/without pages folder - Putting pages in
public/folder
Ready to prove it?
Pass the test and this pattern moves unknown
