|
| 1 | +import { h, FunctionalComponent } from "preact"; |
| 2 | +import { Router, Route } from "preact-iso"; |
| 3 | + |
| 4 | +const A: FunctionalComponent = () => <div>A</div>; |
| 5 | +const B: FunctionalComponent = () => <div>B</div>; |
| 6 | +const C: FunctionalComponent = () => <div>C</div>; |
| 7 | + |
| 8 | +export function RoutingTestCases() { |
| 9 | + return ( |
| 10 | + <> |
| 11 | + {/* ========================================= |
| 12 | + CASE GROUP 1: <Route /> (official API) |
| 13 | + ========================================= */} |
| 14 | + |
| 15 | + {/* Case 1 */} |
| 16 | + {/* (1) SHOULD work: yes */} |
| 17 | + {/* (2) DOES work with official d.ts: yes */} |
| 18 | + <Route path="/a" component={A} /> |
| 19 | + |
| 20 | + {/* Case 2 */} |
| 21 | + {/* (1) SHOULD work: yes */} |
| 22 | + {/* (2) DOES work with official d.ts: yes */} |
| 23 | + <Route default component={B} /> |
| 24 | + |
| 25 | + {/* Case 3 */} |
| 26 | + {/* (1) SHOULD work: no */} |
| 27 | + {/* (2) DOES work with official d.ts: no */} |
| 28 | + {/* @ts-expect-error */} |
| 29 | + <Route /> |
| 30 | + |
| 31 | + {/* Case 4 */} |
| 32 | + {/* (1) SHOULD work: no */} |
| 33 | + {/* (2) DOES work with official d.ts: no */} |
| 34 | + {/* @ts-expect-error */} |
| 35 | + <Route path="/bad" default component={A} /> |
| 36 | + |
| 37 | + {/* ========================================= |
| 38 | + CASE GROUP 2: Arbitrary components inside <Router> |
| 39 | + ========================================= */} |
| 40 | + |
| 41 | + <Router> |
| 42 | + {/* Case 5 */} |
| 43 | + {/* (1) SHOULD work: yes */} |
| 44 | + {/* (2) DOES work with official d.ts: yes */} |
| 45 | + <A /> |
| 46 | + |
| 47 | + {/* Case 6 */} |
| 48 | + {/* (1) SHOULD work: runtime yes, type-safety debatable */} |
| 49 | + {/* (2) DOES work with official d.ts: no */} |
| 50 | + {/* @ts-expect-error */} |
| 51 | + <A path="/a" /> |
| 52 | + |
| 53 | + {/* Case 7 */} |
| 54 | + {/* (1) SHOULD work: runtime yes, type-safety debatable */} |
| 55 | + {/* (2) DOES work with official d.ts: no */} |
| 56 | + {/* @ts-expect-error */} |
| 57 | + <B default /> |
| 58 | + |
| 59 | + {/* Case 8 */} |
| 60 | + {/* (1) SHOULD work: no */} |
| 61 | + {/* (2) DOES work with official d.ts: no */} |
| 62 | + {/* @ts-expect-error */} |
| 63 | + <C path="/c" default /> |
| 64 | + |
| 65 | + {/* Case 9 */} |
| 66 | + {/* (1) SHOULD work: yes */} |
| 67 | + {/* (2) DOES work with official d.ts: yes */} |
| 68 | + <C /> |
| 69 | + </Router> |
| 70 | + </> |
| 71 | + ); |
| 72 | +} |
0 commit comments