# Vite Plugin: Automatic File-based Routing 🚦
SigPro provides an optional Vite plugin that automatically generates routes based on your file structure. No configuration needed - just create pages and they're instantly available with the correct paths.
## Why Use This Plugin?
While SigPro's router works perfectly with manually defined routes, this plugin:
- **Eliminates boilerplate** - No need to write route configurations
- **Enforces conventions** - Consistent URL structure across your app
- **Supports dynamic routes** - Use `[param]` syntax for parameters
- **Automatic code-splitting** - Each page becomes a separate chunk
- **Type-safe** (with JSDoc) - Routes follow your file structure
## Installation
The plugin is included with SigPro, but you need to add it to your Vite config:
```javascript
// vite.config.js
import { defineConfig } from 'vite';
import { sigproRouter } from 'sigpro/vite';
export default defineConfig({
plugins: [sigproRouter()]
});
```
## How It Works
The plugin scans your `src/pages` directory and automatically generates routes based on the file structure:
```
src/pages/
├── index.js → '/'
├── about.js → '/about'
├── blog/
│ ├── index.js → '/blog'
│ └── [slug].js → '/blog/:slug'
└── users/
├── [id].js → '/users/:id'
└── [id]/edit.js → '/users/:id/edit'
```
## Usage
### 1. Enable the Plugin
Add the plugin to your Vite config as shown above.
### 2. Import the Generated Routes
```javascript
// main.js
import { $, html } from 'sigpro';
import { routes } from 'virtual:sigpro-routes';
// Use the generated routes directly
const router = $.router(routes);
document.body.appendChild(router);
```
### 3. Create Pages
```javascript
// src/pages/index.js
import { $, html } from 'sigpro';
export default () => {
return html`