Skip to main content
File-based routing allows you to define pages by placing components in a directory structure, eliminating the need for explicit defineModule() and defineResource() calls. This approach is similar to Next.js’s App Router.

Overview

Instead of manually assembling module/resource hierarchies, you define pages as files in a pages/ directory. The route path is automatically derived from the directory structure.

Setup

1

Configure Vite plugin

Add the appShellRoutes plugin to your Vite config:
2

Create pages directory

Create a src/pages/ directory in your project.
3

Use AppShell without modules prop

No configuration needed—pages are automatically discovered:
Pages are automatically discovered and injected—no modules prop required!

Page components

Minimal example

The simplest page is just a default-exported component:

Full example

Use the appShellPageProps static field to configure metadata and guards:

AppShellPageProps type

Path conventions

Examples

Use (parentheses) for route grouping without affecting the URL path. Use _underscore for shared code that shouldn’t be routed.

Dynamic parameters

Use square brackets for dynamic route segments:

Multiple parameters

Converts to route: /orders/:orderId/items/:itemId

Route guards

Guards are not automatically inherited from parent pages. Each page must explicitly define its own guards:

Reusable guards

To share common guards across pages, compose them from a shared module:
Use in pages:

Typed routes

Enable generateTypedRoutes to generate type-safe route helpers:
This generates src/routes.generated.ts with a paths helper:

Type-safe navigation

Learn more about typed routes

Comparison with legacy API

Before: Explicit hierarchy

After: File-based pages

Concept mapping

Compatibility

File-based pages and explicit modules prop are mutually exclusive.

Valid patterns

No plugin + no modules = runtime error: “No routes configured”

Migration guide

To migrate from defineModule/defineResource to file-based routing:
1

Add Vite plugin

2

Create pages directory structure

  • Map each module to a top-level directory
  • Map each resource to a subdirectory with page.tsx
  • Use [param] for dynamic segments
3

Move component and metadata

4

Remove modules prop

Once all pages are migrated, remove the modules prop from <AppShell>

Routing and navigation

Learn about client-side navigation and typed routes

Modules and resources

Understand the legacy explicit configuration approach