# Pages API ๐
Pages in SigPro are special components designed for route-based navigation with **automatic cleanup**. When you navigate away from a page, all signals, effects, and event listeners created within that page are automatically cleaned up - no memory leaks, no manual cleanup needed.
## `$.page(setupFunction)`
Creates a page with automatic cleanup of all signals and effects when navigated away.
```javascript
import { $, html } from 'sigpro';
export default $.page(() => {
// All signals and effects created here
// will be automatically cleaned up on navigation
const count = $(0);
$.effect(() => {
console.log(`Count: ${count()}`);
});
return html`
My Page
Count: ${count}
`;
});
```
## ๐ API Reference
| Parameter | Type | Description |
|-----------|------|-------------|
| `setupFunction` | `Function` | Function that returns the page content. Receives context object with `params` and `onUnmount` |
### Context Object Properties
| Property | Type | Description |
|----------|------|-------------|
| `params` | `Object` | Route parameters passed to the page |
| `onUnmount` | `Function` | Register cleanup callbacks (alternative to automatic cleanup) |
## ๐ฏ Basic Usage
### Simple Page
```javascript
// pages/home.js
import { $, html } from 'sigpro';
export default $.page(() => {
const title = $('Welcome to SigPro');
return html`
${title}
This page will clean itself up when you navigate away.
`;
});
```
## ๐ Summary
| Feature | Description |
|---------|-------------|
| **Automatic Cleanup** | All signals, effects, and resources auto-cleaned on navigation |
| **Memory Safe** | No memory leaks, even with complex nested effects |
| **Router Integration** | Designed to work perfectly with `$.router` |
| **Parameters** | Access route parameters via `params` object |
| **Manual Cleanup** | `onUnmount` for custom cleanup needs |
| **Zero Configuration** | Just wrap your page in `$.page()` and it works |
---
> **Pro Tip:** Always wrap route-based views in `$.page()` to ensure proper cleanup. This prevents memory leaks and ensures your app stays performant even after many navigation changes.