https://github.com/brycerussell/astro-pages
Add custom file based routing directories in Astro
https://github.com/brycerussell/astro-pages
Last synced: 3 months ago
JSON representation
Add custom file based routing directories in Astro
- Host: GitHub
- URL: https://github.com/brycerussell/astro-pages
- Owner: BryceRussell
- License: unlicense
- Created: 2024-02-08T05:38:37.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-10T00:29:25.000Z (over 1 year ago)
- Last Synced: 2025-09-13T00:10:05.936Z (9 months ago)
- Language: TypeScript
- Size: 306 KB
- Stars: 20
- Watchers: 1
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `astro-pages`
[](https://www.npmjs.com/package/astro-pages)
[](https://www.npmjs.com/package/astro-pages)
Add custom file based routing directories in Astro
### Examples
#### Astro Integration
```ts
// astro.config.mjs
import { defineConfig } from 'astro/config';
import pages from 'astro-pages';
export default defineConfig({
// Inject pages inside 'src/routes'
integrations: [ pages('routes') ],
});
```
#### Standalone Utility
```ts
// package/index.ts
import type { AstroIntegration } from 'astro';
import { addPageDir } from 'astro-pages';
export default function(options): AstroIntegration {
return {
name: 'astro-pages',
hooks: {
'astro:config:setup': ({ config, logger, injectRoute }) => {
const pageConfig = {
cwd: import.meta.url,
dir: 'pages',
config,
logger
}
const {
pages,
injectPages
} = addPageDir(pageConfig)
// Injects pages inside 'package/pages'
injectPages(injectRoute)
}
}
}
}
```