0.5.1 • Published 2 years ago
@fourcels/vite-plugin-react-pages v0.5.1
vite-plugin-react-pages
File system routing for React applications base react-router, vite
Getting Started
Install
pnpm add @fourcels/vite-plugin-react-pages react-router react-router-domVite config
Add to your vite.config.js:
import pages from "@fourcels/vite-plugin-react-pages";
export default {
plugins: [
// ...
pages(),
],
};Overview
By default a page is a
React Router lazy component
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.
import React from "react";
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import routes from "~pages";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<RouterProvider router={createBrowserRouter(routes)} />
</React.StrictMode>,
);Type
// vite-env.d.ts
/// <reference types="@fourcels/vite-plugin-react-pages/client" />Route Style
layout.{tsx,jsx,ts,js}=> layout pagepage.{tsx,jsx,ts,js}=> index page404.{tsx,jsx,ts,js}=> not found page_lib=> private folder (underscore prefix)(layout)=> Layout Routes[id]=>:idDynamic Segments[[id]]=>:id?Optional Segments[...slug]=>*Splats{task}=>task?Optional Static Segments
Example:
# 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.tsx0.4.8
2 years ago
0.4.17
2 years ago
0.4.18
2 years ago
0.4.15
2 years ago
0.4.16
2 years ago
0.4.14
2 years ago
0.3.0
2 years ago
0.4.19
2 years ago
0.4.4
2 years ago
0.4.3
2 years ago
0.5.1
2 years ago
0.4.2
2 years ago
0.2.13
2 years ago
0.2.12
3 years ago
0.2.11
3 years ago
0.2.10
3 years ago
0.2.9
3 years ago
0.2.8
3 years ago
0.2.7
3 years ago
0.2.0
3 years ago