Logo
Section 1 / 12

使用 Astro 的文件路由创建页面

了解 Astro 的文件路由机制、URL 生成、静态路由以及页面间的导航。

导入

使用 Astro 的文件路由创建页面

了解 Astro 的文件路由机制、URL 生成、静态路由以及页面间的导航。

文件生成的路由
src/pages/index.astrodomain.com/
src/pages/contact.astrodomain.com/contact
src/pages/contact/index.astrodomain.com/contact
src/pages/contact/john.astrodomain.com/contact/john

No configuration found for ID: 18be07c231e1f4b4e01b7053c7c3fee817316e6b0640baf53f99aa75d57cc959

Astro构建后生成的静态资源

1/dist 2 /_astro 3 /assets 4 /contact 5 index.html 6 index.html
1import { defineConfig } from 'astro/config'; 2 3// https://astro.build/config 4export default defineConfig({ 5 site: 'https://example.com', 6 build: { 7 format: 'file' 8 } 9});
...
构建后的生成路由

No configuration found for ID: 9127ca24e2835831b31fd27ba48febd24c9f1ac3dfad29ee41cd5dfa55daee0c

1<!-- 首页: --> 2<a href="/contact">联系</a> 3 4<!-- 联系页: --> 5<a href="/">首页</a>
1<!-- 首页: --> 2<a href="/contact">联系</a> 3 4<!-- 联系页: --> 5<a href="/">首页</a>

结论

如何在 Astro 中使用静态资源