Skip to content

Add custom file based routing directories in Astro

License

Notifications You must be signed in to change notification settings

BryceRussell/astro-pages

Repository files navigation

astro-pages

npm version readme

Add custom file based routing directories in Astro

Examples

Astro Integration

// 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

// 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)

      }
    }
  }
}

About

Add custom file based routing directories in Astro

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •