Skip to main content
The Router plugin is Scully’s default fallback plugin for handling routes that don’t have a specific route type configured. It’s the simplest router plugin and is automatically used when no other plugin is specified.

Overview

The Router plugin:
  • Serves as the default router when no type is specified
  • Handles static routes without parameters
  • Returns routes as-is without transformation
  • Requires no configuration
  • Automatically registered in Scully

How It Works

The Router plugin is extremely simple. When invoked, it:
  1. Receives a route string
  2. Returns the route wrapped in a HandledRoute object
  3. Performs no data fetching or transformation
This makes it perfect for static routes that don’t need dynamic data.

Usage

Automatic Usage

The Router plugin is used automatically for routes without a configured type:
import { ScullyConfig } from '@scullyio/scully';

export const config: ScullyConfig = {
  routes: {
    '/about': {
      type: 'default'
    }
  }
};
You can also omit the configuration entirely for simple static routes, and Scully will handle them with the default router.

Explicit Usage

While not required, you can explicitly specify the default router:
export const config: ScullyConfig = {
  routes: {
    '/contact': {
      type: 'default'
    },
    '/privacy': {
      type: 'default'
    },
    '/terms': {
      type: 'default'
    }
  }
};

Configuration

The Router plugin requires no configuration options. It accepts only the route string and returns it immediately.
This plugin is registered with the name 'default' in Scully’s plugin repository.

When to Use

Use the Router plugin (implicitly or explicitly) when you have:
  • Static pages: Pages without dynamic parameters
  • Simple routes: Routes like /about, /contact, /faq
  • No data fetching: Pages that don’t need external data
  • Fixed content: Content that doesn’t change based on parameters

Examples

Static Marketing Pages

export const config: ScullyConfig = {
  routes: {
    '/': { type: 'default' },
    '/about': { type: 'default' },
    '/services': { type: 'default' },
    '/contact': { type: 'default' }
  }
};

Mixed Configuration

Combine static routes with dynamic ones:
export const config: ScullyConfig = {
  routes: {
    // Static routes (default plugin)
    '/': { type: 'default' },
    '/about': { type: 'default' },
    
    // Dynamic routes (other plugins)
    '/blog/:slug': {
      type: 'contentFolder',
      slug: {
        folder: './blog'
      }
    },
    '/products/:id': {
      type: 'json',
      id: {
        url: 'https://api.example.com/products'
      }
    }
  }
};

Implementation

The plugin’s implementation is minimal:
import { registerPlugin } from '../pluginManagement/pluginRepository';
import { HandledRoute } from './handledRoute.interface';

async function defaultRouterPlugin(route: string) {
  return [{ route } as HandledRoute];
}

registerPlugin('router', 'default', defaultRouterPlugin);
This simplicity makes it fast and reliable for static routes.

Comparison with Other Router Plugins

Router Plugin (Default):
  • No file system scanning
  • No data extraction
  • Single static route
  • No configuration needed
Content Folder Plugin:
  • Scans directories
  • Reads file content
  • Generates multiple routes
  • Requires folder configuration
Router Plugin (Default):
  • No HTTP requests
  • No external data
  • Immediate return
  • No async operations
JSON Plugin:
  • Fetches API data
  • Handles responses
  • Generates multiple routes
  • Requires URL configuration

Best Practices

1

Use for static pages

Reserve the default router for truly static pages that never need dynamic content.
2

Explicit when needed

While implicit usage works, explicitly setting type: 'default' can make your configuration clearer.
3

Combine with other plugins

Mix static and dynamic routes freely in your configuration.
For pages that will never have dynamic content, using the default router plugin keeps your build fast and simple.

Route Handling Flow

When Scully encounters a route:
  1. Check for explicit type: If type is specified, use that plugin
  2. Check for parameters: If the route has :param segments, look for appropriate plugin
  3. Fall back to default: If no type is specified and no parameters exist, use the Router plugin

Performance

The Router plugin is the fastest router option because:
  • No I/O operations
  • No network requests
  • No file system access
  • Immediate synchronous return
Despite being async in signature, the plugin returns immediately without await points.

Content Folder Plugin

Generate routes from local content files

JSON Plugin

Fetch data from JSON APIs

Build docs developers (and LLMs) love