farm-plugin-pagerouter
v0.1.1
Published
File-based page router plugin for Farm, Next.js-style routing with layouts
Maintainers
Readme
farm-plugin-pagerouter
File-based page router plugin for FarmFE (React + react-router-dom).
Install
npm install farm-plugin-pagerouterPeer dependencies: Your app must provide
reactandreact-router-dom.
Convention
Default pages directory:
src/pagesSupported conventions:
index.tsx→ index route (/)about.tsx→/about_layout.tsx→ layout wrapper for sibling routes[param].tsx→ dynamic segment (/user/:param)blog/_layout.tsx→ nested layout for/blog/*
The plugin generates the virtual module:
import { AppRouter, Outlet } from 'virtual:farm-plugin-pagerouter'Example
import pageRouter from 'farm-plugin-pagerouter'
export default {
plugins: [pageRouter()],
}Then render the generated router:
import { AppRouter } from 'virtual:farm-plugin-pagerouter'
export function Main() {
return <AppRouter />
}API
farmPluginPageRouter(options?)
pagesDir— Directory to scan, relative to project root. Default:'src/pages'
HMR
When page files are added or modified, the virtual router module is automatically invalidated and regenerated. No full reload needed — the route tree updates on the fly.
Notes
This package is used as a routing generator, not as a separate runtime library. The route tree is derived from the app file structure at build/load time.
The consuming app should provide the React routing runtime itself, including react-router-dom.
