Skip to content

Commit

Permalink
feat: 补充文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liujiayii committed Nov 15, 2024
1 parent e3b31b9 commit c0d0d9f
Showing 1 changed file with 98 additions and 8 deletions.
106 changes: 98 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,110 @@

- 🔥 基于文件系统的约定式路由解决方案。
- 🔥 基于`unplugin``vite-plugin-pages`进行了移植,能同时支持`vite``webpack``rsbuild``farm`等构建框架,并同时支持`react``vue``solid`三大框架。
- ⚠️ 尚在开发中,还不能正常使用,请勿使用。个人仅测试了`vue+vite``vue`+`rsbuild``react`+`vite``react`+`rsbuild`
- ⚠️ 尚在开发中,可能有的框架无法正常使用,个人测试了`vue`+`vite``vue`+`rsbuild``react`+`vite``react`+`rsbuild`可用

---

## 友情链接
## 已知问题
- 新增路由无法热更,需要手动重启项目(可能是vite对js文件请求进行了缓存?)
- 配置文件可能有ts错误提示(比较影响体验,需要优先解决)
- 测试用例无法通过(影响GitHub观感,影响renovate automerge)

- [unplugin](https://github.com/unjs/unplugin)
- [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages)
---

## 📦 安装
## 📦 安装 & 使用

```bash
pnpm i unplugin-convention-routes
```

## 🔨 示例
<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Routes from 'unplugin-convention-routes/vite'

export default defineConfig({
plugins: [
Routes({ /* options */ }),
],
})
```
</details>
<details>
<summary>Rsbuild</summary><br>

```ts
// rsbuild.config.ts
import Routes from 'unplugin-convention-routes/rspack'

export default defineConfig({
tools: {
rspack: {
plugins: [
Pages({ /* options */ }),
],
},
},
})
```
</details>
<details>
<summary>React</summary><br>

```ts
// env.d.ts
/// <reference types="unplugin-convention-routes/client-react.d.ts" />
```
```tsx
import routes from '~unplugin-convention-routes/react'
import { StrictMode, Suspense } from 'react'
import { createRoot } from 'react-dom/client'
import {
BrowserRouter,
useRoutes,
} from 'react-router-dom'

function App() {
return (
<Suspense fallback={<p>Loading...</p>}>
{useRoutes(routes)}
</Suspense>
)
}

const app = createRoot(document.getElementById('root')!)

app.render(
<StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</StrictMode>,
)
```
</details>
<details>
<summary>Vue</summary><br/>

```ts
// env.d.ts
/// <reference types="unplugin-convention-routes/client-vue.d.ts" />
```
```ts
import routes from '~unplugin-convention-routes/vue'
import { createRouter } from 'vue-router'

const router = createRouter({
// ...
routes,
})
```
</details>

## 🔨 示例项目
- https://github.com/liujiayii/unplugin-convention-routes/tree/main/examples

## 友情链接

- [unplugin](https://github.com/unjs/unplugin)
- [vite-plugin-pages](https://github.com/hannoeru/vite-plugin-pages)

0 comments on commit c0d0d9f

Please sign in to comment.