https://github.com/aquaticcalf/file-system-router
a file based routing system for react router
https://github.com/aquaticcalf/file-system-router
based file react router routing
Last synced: 10 months ago
JSON representation
a file based routing system for react router
- Host: GitHub
- URL: https://github.com/aquaticcalf/file-system-router
- Owner: aquaticcalf
- License: mit
- Created: 2025-02-17T16:52:43.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-15T19:37:09.000Z (about 1 year ago)
- Last Synced: 2025-03-28T06:18:37.451Z (about 1 year ago)
- Topics: based, file, react, router, routing
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/file-system-router
- Size: 21.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
## file system router
### installation :
```bash
npm install file-system-router
```
### usage in your app :
```jsx
// App.jsx
import { BrowserRouter as Router } from 'react-router-dom'
import { FileSystemRouter } from 'file-system-router'
// vite users:
const pages = import.meta.glob('./pages/**/*.jsx', { eager: true })
// webpack users:
// const pages = require.context('./pages', true, /\.jsx$/)
export default function App() {
return (
)
}
```
### file structure convention :
```
pages/
index.jsx -> /
about.jsx -> /about
blog/
index.jsx -> /blog
[id].jsx -> /blog/:id
author/
[author_name]/
name.jsx -> /author/:author_name/name
```
### features :
1. automatically converts files to routes
2. supports dynamic parameters with `[param].jsx`
3. supports nested routes based on your file and directory structure, `[param]/example.jsx`
4. handles index routes with `index.jsx`
### for your page components :
```jsx
// pages/blog/[id].jsx
import { useParams } from 'react-router-dom'
export default function BlogPost() {
const { id } = useParams()
return
blog post : {id}
}
// pages/author/[author_name]/name.jsx
import { useParams } from 'react-router-dom'
export default function AuthorName() {
const { author_name } = useParams()
return
author name : {author_name}
}
```