An open API service indexing awesome lists of open source software.

https://github.com/hunghg255/rsbuild-react-generate-pages

A rsbuild plugin generates pages for React applications.
https://github.com/hunghg255/rsbuild-react-generate-pages

generate-pages react react-router-dom rsbuild

Last synced: 7 months ago
JSON representation

A rsbuild plugin generates pages for React applications.

Awesome Lists containing this project

README

          



logo


A rsbuild plugin generates pages for React applications.


NPM Version
NPM Downloads
Minizip
Contributors
License

## 📦 Installation

```bash
npm install rsbuild-react-generate-pages -D
```

## 🦄 Usage

### Configuration `rsbuild.config.ts`

```ts
import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginReactGeneratePages} from 'rsbuild-react-generate-pages';

export default defineConfig({
plugins: [pluginReactGeneratePages(), pluginReact()],
});
```

## Overview

By default a page is a
[React Router lazy component](https://reactrouter.com/en/main/route/lazy)
exported from a `.tsx`, `.jsx`, `.ts`, `.js` file in the `src/pages` directory.

You can access the generated routes by importing the `~pages` module in your
application.

```tsx
import ReactDOM from 'react-dom/client'
import { RouterProvider, createBrowserRouter } from 'react-router-dom'

import routes from '~pages'

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(

)
```

**Type**

```ts
// env.d.ts
///
```

## Route Style

- `layout.{tsx,jsx,ts,js}` => layout page
- `page.{tsx,jsx,ts,js}` => index page
- `404.{tsx,jsx,ts,js}` => not found page
- `_lib` => private folder (underscore prefix)
- `(layout)` =>
[Layout Routes](https://reactrouter.com/en/main/route/route#layout-routes)
- `[id]` => `:id`
[Dynamic Segments](https://reactrouter.com/en/main/route/route#dynamic-segments)
- `[[id]]` => `:id?`
[Optional Segments](https://reactrouter.com/en/main/route/route#optional-segments)
- `[...slug]` => `*`
[Splats](https://reactrouter.com/en/main/route/route#splats)
- `{task}` => `task?`
[Optional Static Segments](https://reactrouter.com/en/main/route/route#dynamic-segments)

**Example:**

[exmaple](/playground)

```bash
# folder structure
src/pages/
├── (dashboard)
│ ├── [...slug]
│ │ └── page.tsx
│ ├── posts
│ │ ├── [id]
│ │ │ └── page.tsx
│ │ └── page.tsx
│ ├── layout.tsx
│ └── page.tsx
├── about
│ └── [[lang]]
│ └── page.tsx
├── 404.tsx
├── layout.tsx
└── page.tsx
```