Skip to content

Commit cd8358d

Browse files
committed
replace react-router using wouter
1 parent d9fe2eb commit cd8358d

File tree

8 files changed

+86
-171
lines changed

8 files changed

+86
-171
lines changed

.changeset/slick-goats-find.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'orga-build': patch
3+
---
4+
5+
replace react-router with wouter

docs/_layout.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export default function Layout({ children }: LayoutProps) {
5959
viewBox="0 0 24 24"
6060
fill="none"
6161
stroke="currentColor"
62-
stroke-width="2"
63-
stroke-linecap="round"
64-
stroke-linejoin="round"
62+
strokeWidth="2"
63+
strokeLinecap="round"
64+
strokeLinejoin="round"
6565
>
6666
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
6767
<path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" />

packages/orga-build/lib/app.jsx

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { createElement } from 'react'
21
import pages from '@orga-build/pages'
32
import layouts from '@orga-build/layouts'
43
import * as components from '@orga-build/components'
5-
import { Link, useRoutes } from 'react-router'
4+
import { Route, Switch, Link } from 'wouter'
65

76
export function App() {
87
const _pages = Object.entries(pages).map(([path, page]) => {
@@ -16,19 +15,13 @@ export function App() {
1615
const layoutIds = Object.keys(layouts)
1716
.filter((key) => path.startsWith(key))
1817
.sort((a, b) => -a.localeCompare(b))
19-
let element = createElement(page.default, {
20-
components: { ...components, Link }
21-
})
18+
let element = <page.default components={{ ...components, Link, a: Link }} />
2219
for (const layoutId of layoutIds) {
23-
element = createElement(
24-
layouts[layoutId],
25-
{
26-
title: page.title,
27-
slug: path,
28-
...page,
29-
pages: _pages
30-
},
31-
element
20+
const Layout = layouts[layoutId]
21+
element = (
22+
<Layout title={page.title} slug={path} pages={_pages} {...page}>
23+
{element}
24+
</Layout>
3225
)
3326
}
3427
return {
@@ -37,5 +30,15 @@ export function App() {
3730
}
3831
})
3932

40-
return useRoutes(pageRoutes)
33+
return (
34+
<Switch>
35+
{pageRoutes.map((route) => {
36+
return (
37+
<Route key={`r-${route.path}`} path={route.path}>
38+
{route.element}
39+
</Route>
40+
)
41+
})}
42+
</Switch>
43+
)
4144
}

packages/orga-build/lib/client.jsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { hydrateRoot } from 'react-dom/client'
2-
import { BrowserRouter } from 'react-router'
2+
import { Router } from 'wouter'
33
import { App } from './app.jsx'
44

55
const ssr = window._ssr
66

7-
hydrate()
8-
9-
function hydrate() {
10-
const container = document.getElementById('root')
11-
// const page = pages[ssr.routePath]
12-
hydrateRoot(
13-
container,
14-
<BrowserRouter basename="/">
15-
<App />
16-
</BrowserRouter>
17-
)
18-
}
7+
hydrateRoot(
8+
document.getElementById('root'),
9+
<Router>
10+
<App />
11+
</Router>
12+
)

packages/orga-build/lib/csr.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react'
22
import { createRoot } from 'react-dom/client'
33
import { App } from './app.jsx'
4-
import { BrowserRouter } from 'react-router'
4+
import { Router } from 'wouter'
55

66
const container = document.getElementById('root')
77
const root = createRoot(container)
88
root.render(
9-
<BrowserRouter basename="/">
9+
<Router>
1010
<App />
11-
</BrowserRouter>
11+
</Router>
1212
)

packages/orga-build/lib/ssr.jsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pages from '@orga-build/pages'
22
import { renderToString } from 'react-dom/server'
3-
import { StaticRouter } from 'react-router'
43
import { App } from './app.jsx'
4+
import { Router } from 'wouter'
55

66
export { pages }
77

@@ -14,13 +14,11 @@ export function render(url) {
1414
console.log(`no page found for ${url}`)
1515
return
1616
}
17-
return renderToString(<SSRContent url={url} />)
18-
}
19-
20-
function SSRContent({ url }) {
21-
return (
22-
<StaticRouter location={url}>
17+
const ssrContext = {}
18+
console.log(`rendering ${url}`)
19+
return renderToString(
20+
<Router ssrPath={url} ssrContext={ssrContext}>
2321
<App />
24-
</StaticRouter>
22+
</Router>
2523
)
2624
}

packages/orga-build/package.json

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,15 @@
77
"orga-build": "./cli.js"
88
},
99
"scripts": {},
10-
"files": [
11-
"lib/",
12-
"cli.js",
13-
"index.js",
14-
"index.d.ts",
15-
"index.d.ts.map"
16-
],
10+
"files": ["lib/", "cli.js", "index.js", "index.d.ts", "index.d.ts.map"],
1711
"exports": {
1812
".": {
1913
"types": "./index.d.ts",
2014
"import": "./index.js"
2115
},
2216
"./csr.jsx": "./lib/csr.jsx"
2317
},
24-
"keywords": [
25-
"orgajs",
26-
"org-mode",
27-
"build",
28-
"website",
29-
"react"
30-
],
18+
"keywords": ["orgajs", "org-mode", "build", "website", "react"],
3119
"author": "Xiaoxing Hu <[email protected]>",
3220
"license": "MIT",
3321
"dependencies": {
@@ -40,11 +28,10 @@
4028
"globby": "^14.1.0",
4129
"react": "^19.0.0",
4230
"react-dom": "^19.0.0",
43-
"react-router": "^7.5.1",
4431
"rehype-katex": "^7.0.1",
45-
"serve-handler": "^6.1.6",
4632
"unist-util-visit-parents": "^6.0.1",
47-
"vite": "6.3.2"
33+
"vite": "6.3.2",
34+
"wouter": "^3.7.0"
4835
},
4936
"devDependencies": {
5037
"@orgajs/orgx": "workspace:^",
@@ -53,7 +40,6 @@
5340
"@types/node": "^22.13.1",
5441
"@types/react": "^19.0.8",
5542
"@types/react-dom": "^19.0.3",
56-
"@types/serve-handler": "^6.1.4",
5743
"orga": "workspace:^"
5844
}
5945
}

0 commit comments

Comments
 (0)