Generouted
Generated file-based routes for Vite
Install / Use
/learn @oedotme/GeneroutedREADME
Generouted
Generated file-based routes for Vite
<details> <summary><b>Motivation</b></summary> <br>I enjoyed using file-based routing since I tried Next.js (pages directory). After applying the same concept with Vite and client-side applications, I started writing blog posts covering the implementation of client-side file-based routing with React Router which was packaged later as generouted.
Today generouted brings many features, supports multiple frameworks and routers, and inspires ideas and conventions from Next.js, Remix, Expo, Docusaurus, SvelteKit and more.
generouted uses Vite's glob import API to list the routes within the src/pages directory and generates the routes tree and modals based on generouted's conventions.
There are also Vite plugins available for some integrations to provide type-safe components/hooks/utils through code-generation.
<br> </details> <br>Features
- 📁 Client-side file-based routing
- ⚡ Powered by Vite
- ✨ React support with
react-routeror@tanstack/router🧪 or@tanstack/react-location🚨 - ✨ Solid support with
@solidjs/router - ✨ File-based MDX routes with React or Solid, requires
@mdx-js/rollupinstallation and setup - 🔐 Type-safe navigation
- 🚀 Type-safe global modals
- 💤 Route-based code-splitting and lazy-loading
- 📄 Route-based data loaders and actions
- 💣 Route-based error boundary
- 📂 Nested layouts
- 🫙 Pathless layout groups
- ❓ Optional static and dynamic routes
- 💭 Ignored routes per file or directory
Online explorer
- ⚡ Visit
generouted's interactive playground via StackBlitz - 🧩 Explore file-based routing patterns and conventions
- 🔎 Visualize the routes layouts and the resolved routes paths
- 📝 Update
src/pages/files and see your changes reflecting
Getting started
<details open="true"> <summary><b>React Router</b></summary>React Router
In case you don't have a Vite project with React and TypeScript, check Vite documentation to start a new project.
Installation
pnpm add @generouted/react-router react-router
Setup
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import generouted from '@generouted/react-router/plugin'
export default defineConfig({ plugins: [react(), generouted()] })
Usage
// src/main.tsx
import { createRoot } from 'react-dom/client'
import { Routes } from '@generouted/react-router'
createRoot(document.getElementById('root')!).render(<Routes />)
Adding pages
Add the home page by creating a new file src/pages/index.tsx → /, then export a default component:
export default function Home() {
return <h1>Home</h1>
}
Check the routing conventions section below.
Docs
You can find more details about type-safe navigation and global modals at @generouted/react-router docs.
Examples
- Type-safe navigation + global modals
- Custom integration
- Custom integration with custom path
- MDX routes
Solid Router
In case you don't have a Vite project with Solid and TypeScript, check Vite documentation to start a new project.
Installation
pnpm add @generouted/solid-router @solidjs/router
Setup
// vite.config.ts
import { defineConfig } from 'vite'
import solid from 'vite-plugin-solid'
import generouted from '@generouted/solid-router/plugin'
export default defineConfig({ plugins: [solid(), generouted()] })
Usage
// src/main.tsx
import { render } from 'solid-js/web'
import { Routes } from '@generouted/solid-router'
render(Routes, document.getElementById('root')!)
Adding pages
Add the home page by creating a new file src/pages/index.tsx → /, then export a default component:
export default function Home() {
return <h1>Home</h1>
}
See more about generouted routing conventions below.
Docs
You can find more details about type-safe navigation and global modals at @generouted/solid-router docs.
Examples
<br> </details> <details> <summary><b>TanStack React Router — In-progress experimental support 🧪</b></summary>TanStack React Router — In-progress experimental support 🧪
Examples
<br> </details> <details> <summary><b>React Location — Deprecated 🚨</b></summary>React Location — Deprecated 🚨
In case you don't have a Vite project with React and TypeScript, check Vite documentation to start a new project.
Installation
pnpm add generouted @tanstack/react-location
Usage
// src/main.tsx
import { createRoot } from 'react-dom/client'
import { Routes } from 'generouted/react-location'
createRoot(document.getElementById('root')!).render(<Routes />)
Adding pages
Add the home page by creating a new file src/pages/index.tsx → /, then export a default component:
export default function Home() {
return <h1>Home</h1>
}
Examples
<br> </details> <br>Conventions
File and directories naming and conventions
- Routes declaration at
src/pages - Supports
.tsx,.jsxand.mdxfile extensions - Optional
src/pages/_app.tsxfor an app level layout - Optional
src/pages/404.tsxfor a custom not-found page
Index routes
src/pages/index.tsx→/src/pages/posts/index.tsx→/posts
Nested routes
src/pages/posts/2022/index.tsx→/posts/2022src/pages/posts/2022/resolutions.tsx→/posts/2022/resolutions
Dynamic routes
src/pages/posts/[slug].tsx→/posts/:slugsrc/pages/posts/[slug]/tags.tsx→/posts/:slug/tagssrc/pages/posts/[...all].tsx→/posts/*
Nested layouts
- By defining
_layout.tsxin any nested directory →src/pages/posts/_layout.tsx - Requires using an
<Outlet />component to render layout children - All the files within the
src/pages/posts/directory in this case, will be wrapped with that layout
Nested URLs without nested layouts
- Route file should be outside of the nested layout directory
- Include dots
.between the segments to be converted to forward slashes src/pages/posts.nested.as.url.not.layout.tsx→/posts/nested/as/url/not/layout
Pathless layouts
- Similar to nested layouts for layout definition
- By wrapping the parent directory with parentheses
() src/pages/(auth)/_layout.tsxsrc/pages/(auth)/login.tsx→/login- Layout parent directory name is not included in the routes paths
Global modals
- By prefixing the file name with a plus sign
+(thinking the modal is an extra route overlaying the current route) - Modals navigation available via the
useModals()hook src/pages/+info.tsx→/infosrc/pages/+checkout/+details.tsx→/checkout/detailssrc/pages/+checkout/+payment.tsx→/checkout/payment
Optional segments
- By prefixing a route segment with a minus sign
-(thinking the segment can be subtracted or removed from the route path) src/pages/-en/about.tsx→/en?/about→/en/about,/aboutsrc/pages/-[lang]/about.tsx→/:lang?/about→/en/about,/fr/about,/about
Ignored routes
- Any directory or file starts with an underscore
_will be ignored src/pages/_ignored.tsxsrc/pages/posts/_components/button.tsxsrc/pages/posts/_components/link.tsx
Page exports
- Required page component
export default Component() {...} - Optional page loader function
export const Loader = () => {...} - Optional page action function
export const Action = () => {...} - Optional suspense-based pending component
export const Pending = () => {...} - Optional error boundary component `export co
Related Skills
bluebubbles
344.4kUse when you need to send or manage iMessages via BlueBubbles (recommended iMessage integration). Calls go through the generic message tool with channel="bluebubbles".
node-connect
344.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
slack
344.4kUse when you need to control Slack from OpenClaw via the slack tool, including reacting to messages or pinning/unpinning items in Slack channels or DMs.
frontend-design
99.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
