-
-
Notifications
You must be signed in to change notification settings - Fork 883
Expand file tree
/
Copy pathrouter.tsx
More file actions
64 lines (54 loc) · 1.08 KB
/
router.tsx
File metadata and controls
64 lines (54 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import React from 'react';
import {MemoryRouter, Routes, Route, useNavigate} from 'react-router';
import {render, useInput, useApp, Box, Text} from '../../src/index.js';
function Home() {
const {exit} = useApp();
const navigate = useNavigate();
useInput((input, key) => {
if (input === 'q') {
exit();
}
if (key.return) {
void navigate('/about');
}
});
return (
<Box flexDirection="column">
<Text bold color="green">
Home
</Text>
<Text>Press Enter to go to About, or "q" to quit.</Text>
</Box>
);
}
function About() {
const {exit} = useApp();
const navigate = useNavigate();
useInput((input, key) => {
if (input === 'q') {
exit();
}
if (key.return) {
void navigate('/');
}
});
return (
<Box flexDirection="column">
<Text bold color="blue">
About
</Text>
<Text>Press Enter to go back Home, or "q" to quit.</Text>
</Box>
);
}
function App() {
return (
<MemoryRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</MemoryRouter>
);
}
render(<App />);