SkillAgentSearch skills...

Generouted

Generated file-based routes for Vite

Install / Use

/learn @oedotme/Generouted

README

<br> <p align="center"><img src="https://raw.githubusercontent.com/oedotme/generouted/main/logo.svg" alt="generouted" width="280"/></p> <p align="center"> <a href="https://npmjs.com/package/generouted"><img src="https://img.shields.io/npm/v/generouted.svg"/></a> <a href="https://npmjs.com/package/generouted"><img src="https://img.shields.io/npm/l/generouted.svg?color=blue"/></a> <a href="https://stackblitz.com/github.com/oedotme/generouted/tree/main/explorer"><img src="https://img.shields.io/badge/generouted/explorer-StackBlitz-blue"/></a> </p> <p align="center"> <a href="https://npmjs.com/package/generouted"><img src="https://img.shields.io/npm/dm/generouted.svg"/></a> <a href="https://npmjs.com/package/generouted"><img src="https://img.shields.io/npm/dt/generouted.svg"/></a> </p> <br>

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.

<br> </details> <details> <summary><b>How does it work?</b></summary> <br>

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-router or @tanstack/router 🧪 or @tanstack/react-location 🚨
  • ✨ Solid support with @solidjs/router
  • ✨ File-based MDX routes with React or Solid, requires @mdx-js/rollup installation 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
<br>

Online explorer

<br>

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

<br> </details> <details open="true"> <summary><b>Solid Router</b></summary>

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 🧪

Check out the docs here

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, .jsx and .mdx file extensions
  • Optional src/pages/_app.tsx for an app level layout
  • Optional src/pages/404.tsx for 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/2022
  • src/pages/posts/2022/resolutions.tsx/posts/2022/resolutions

Dynamic routes

  • src/pages/posts/[slug].tsx/posts/:slug
  • src/pages/posts/[slug]/tags.tsx/posts/:slug/tags
  • src/pages/posts/[...all].tsx/posts/*

Nested layouts

  • By defining _layout.tsx in 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.tsx
  • src/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/info
  • src/pages/+checkout/+details.tsx/checkout/details
  • src/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, /about
  • src/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.tsx
  • src/pages/posts/_components/button.tsx
  • src/pages/posts/_components/link.tsx
<br>

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

View on GitHub
GitHub Stars1.2k
CategoryDevelopment
Updated2d ago
Forks67

Languages

TypeScript

Security Score

100/100

Audited on Mar 30, 2026

No findings