Performance: Why file-based routing simplifies navigation
This concept affects page load speed and interaction responsiveness by simplifying route management and reducing runtime overhead.
src/pages/home.astro src/pages/about.astro // Astro automatically maps these files to routes without extra code
const routes = [{ path: '/home', component: Home }, { path: '/about', component: About }];
function navigate(path) {
const route = routes.find(r => r.path === path);
if (route) render(route.component);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual route lookup | Minimal | 0 | Low | [!] OK |
| File-based routing | Minimal | 0 | Low | [OK] Good |
src/pages folder?src/pages automatically become routes based on their file names./about/team in Astro?/about/team, you need a folder about with a file inside it for team.src/pages/about/team/index.astro creates the route /about/team because index.astro inside team folder maps to that path.src/pages:index.astro, blog/index.astro, blog/post.astroindex.astro maps to /, blog/index.astro maps to /blog, and blog/post.astro maps to /blog/post.index in URL./contact but your file is named src/pages/contact.astrox. What is the problem?.astro extension to create routes.contact.astrox is not recognized, so no route /contact is created./user/123 using file-based routing. Which file path correctly creates this dynamic route in Astro?[param] in file names to define dynamic route segments.src/pages/user/[id].astro creates a route matching /user/anything where id is dynamic.Pass the test and this pattern moves unknown