22
33[ Web Component] [ 1 ] Router based on [ WebCell] [ 2 ] & [ MobX] [ 3 ]
44
5- [ ![ NPM Dependency] ( https://david-dm.org /EasyWebApp/cell-router.svg )] [ 4 ]
5+ [ ![ NPM Dependency] ( https://img.shields.io/librariesio/github /EasyWebApp/cell-router.svg )] [ 4 ]
66[ ![ CI & CD] ( https://github.com/EasyWebApp/cell-router/actions/workflows/main.yml/badge.svg )] [ 5 ]
77
88[ ![ NPM] ( https://nodei.co/npm/cell-router.png?downloads=true&downloadRank=true&stars=true )] [ 6 ]
@@ -30,21 +30,33 @@ https://web-cell.dev/scaffold/
3030
3131## Installation
3232
33+ ### Command
34+
3335``` shell
34- npm install web-cell cell-router
35- npm install parcel -D
36+ npm install dom-renderer web-cell cell-router
37+ npm install parcel @parcel/config-default @parcel/transformer-typescript-tsc -D
3638```
3739
38- ` tsconfig.json `
40+ ### ` tsconfig.json `
3941
4042``` json
4143{
4244 "compilerOptions" : {
43- "target" : " ES5" ,
44- "experimentalDecorators" : true ,
45- "jsx" : " react" ,
46- "jsxFactory" : " createCell" ,
47- "jsxFragmentFactory" : " Fragment"
45+ "target" : " ES6" ,
46+ "useDefineForClassFields" : true ,
47+ "jsx" : " react-jsx" ,
48+ "jsxImportSource" : " dom-renderer"
49+ }
50+ }
51+ ```
52+
53+ ### ` .parcelrc `
54+
55+ ``` json
56+ {
57+ "extends" : " @parcel/config-default" ,
58+ "transformers" : {
59+ "*.{ts,tsx}" : [" @parcel/transformer-typescript-tsc" ]
4860 }
4961}
5062```
@@ -53,95 +65,84 @@ npm install parcel -D
5365
5466### Sync Pages
5567
56- ` source/index.tsx `
68+ #### ` source/index.tsx `
5769
58- ``` jsx
59- import { documentReady , render , createCell , Fragment } from ' web-cell' ;
60- import { History , PageProps , CellRouter } from ' cell-router/source' ;
70+ ``` tsx
71+ import { DOMRenderer } from ' dom-renderer' ;
72+ import { FC } from ' web-cell' ;
73+ import { createRouter , PageProps } from ' cell-router' ;
6174
62- const history = new History ();
75+ const { Route, Link } = createRouter ();
6376
64- function TestPage ({ path, history, defaultSlot, ... data }: PageProps ) {
65- return (
66- < ul>
67- < li> Path: {path}< / li>
68- < li> Data: {JSON .stringify (data)}< / li>
69- < / ul>
70- );
71- }
77+ const TestPage: FC <PageProps > = ({ path , history , defaultSlot , ... data }) => (
78+ <ul >
79+ <li >Path: { path } </li >
80+ <li >Data: { JSON .stringify (data )} </li >
81+ </ul >
82+ );
7283
73- documentReady .then (() =>
74- render (
75- <>
76- < nav>
77- < a href= " test?a=1" > Test< / a>
78- < a href= " example?b=2" > Example< / a>
79- < / nav>
80- < CellRouter
81- className= " router"
82- history= {history}
83- routes= {[{ paths: [' test' , / ^ example/ ], component: TestPage }]}
84- / >
85- < / >
86- )
84+ new DOMRenderer ().render (
85+ <>
86+ <nav >
87+ <Link to = " test?a=1" >Test</Link >
88+ <Link to = " example/2" >Example</Link >
89+ </nav >
90+ <main className = " router" >
91+ <Route path = " test" component = { TestPage } />
92+ <Route path = " example/:id" component = { TestPage } />
93+ </main >
94+ </>
8795);
8896```
8997
9098### Async Pages
9199
92- ` tsconfig.json `
100+ #### ` tsconfig.json `
93101
94102``` json
95103{
96104 "compilerOptions" : {
97- "module" : " ESNext "
105+ "module" : " ES2020 "
98106 }
99107}
100108```
101109
102- ` source/page/index.ts `
103-
104- ``` javascript
105- export default [
106- {
107- paths: [' ' , ' home' ],
108- component: async () => (await import (' ./Home.tsx' )).default
109- },
110- {
111- paths: [' list' ],
112- component: async () => (await import (' ./List.tsx' )).default
113- }
114- ];
115- ```
110+ #### ` source/index.tsx `
116111
117- ` source/index.tsx `
112+ ``` tsx
113+ import { DOMRenderer } from ' dom-renderer' ;
114+ import { FC , lazy } from ' web-cell' ;
115+ import { createRouter , PageProps } from ' cell-router' ;
118116
119- ``` jsx
120- import { documentReady , render , createCell , Fragment } from ' web-cell' ;
121- import { History , CellRouter } from ' cell-router/source' ;
117+ const { Route, Link } = createRouter ();
122118
123- import routes from ' ./page' ;
124-
125- const history = new History ();
126-
127- documentReady .then (() =>
128- render (
129- <>
130- < nav>
131- < a href= " test?a=1" > Test< / a>
132- < a href= " example?b=2" > Example< / a>
133- < / nav>
134- < CellRouter className= " router" history= {history} routes= {routes} / >
135- < / >
136- )
119+ const TestPage: FC <PageProps > = ({ path , history , defaultSlot , ... data }) => (
120+ <ul >
121+ <li >Path: { path } </li >
122+ <li >Data: { JSON .stringify (data )} </li >
123+ </ul >
124+ );
125+ const AsyncPage = lazy (() => import (' ./Async' ));
126+
127+ new DOMRenderer ().render (
128+ <>
129+ <nav >
130+ <Link to = " test?a=1" >Test</Link >
131+ <Link to = " example/2" >Example</Link >
132+ </nav >
133+ <main className = " router" >
134+ <Route path = " test" component = { TestPage } />
135+ <Route path = " example/:id" component = { AsyncPage } />
136+ </main >
137+ </>
137138);
138139```
139140
140141[ 1 ] : https://www.webcomponents.org/
141142[ 2 ] : https://web-cell.dev/
142- [ 3 ] : https://github.com/mobxjs/mobx/tree/mobx4and5/docs
143- [ 4 ] : https://david-dm.org/EasyWebApp /cell-router
143+ [ 3 ] : https://mobx.js.org/
144+ [ 4 ] : https://libraries.io/npm /cell-router
144145[ 5 ] : https://github.com/EasyWebApp/cell-router/actions/workflows/main.yml
145146[ 6 ] : https://nodei.co/npm/cell-router/
146- [ 7 ] : https://github.com/EasyWebApp/cell-router/blob/v2 /test/source/index.less#L5
147- [ 8 ] : https://github.com/EasyWebApp/cell-router/blob/v2 /test/source/page/index.tsx#L12
147+ [ 7 ] : https://github.com/EasyWebApp/cell-router/blob/b7f98243834f9226088c15b111428e211bbfaa9f /test/source/index.less#L5-L25
148+ [ 8 ] : https://github.com/EasyWebApp/cell-router/blob/b7f98243834f9226088c15b111428e211bbfaa9f /test/source/page/index.tsx#L19-L32
0 commit comments