forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicExample.js
More file actions
106 lines (96 loc) · 2.35 KB
/
BasicExample.js
File metadata and controls
106 lines (96 loc) · 2.35 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import { NativeRouter, Route, Link } from "react-router-native";
function Home() {
return <Text style={styles.header}>Home</Text>;
}
function About() {
return <Text style={styles.header}>About</Text>;
}
function Topic({ match }) {
return <Text style={styles.topic}>{match.params.topicId}</Text>;
}
function Topics({ match }) {
return (
<View>
<Text style={styles.header}>Topics</Text>
<View>
<Link
to={`${match.url}/rendering`}
style={styles.subNavItem}
underlayColor="#f0f4f7"
>
<Text>Rendering with React</Text>
</Link>
<Link
to={`${match.url}/components`}
style={styles.subNavItem}
underlayColor="#f0f4f7"
>
<Text>Components</Text>
</Link>
<Link
to={`${match.url}/props-v-state`}
style={styles.subNavItem}
underlayColor="#f0f4f7"
>
<Text>Props v. State</Text>
</Link>
</View>
<Route path={`${match.url}/:topicId`} component={Topic} />
<Route
exact
path={match.url}
render={() => <Text style={styles.topic}>Please select a topic.</Text>}
/>
</View>
);
}
function App() {
return (
<NativeRouter>
<View style={styles.container}>
<View style={styles.nav}>
<Link to="/" underlayColor="#f0f4f7" style={styles.navItem}>
<Text>Home</Text>
</Link>
<Link to="/about" underlayColor="#f0f4f7" style={styles.navItem}>
<Text>About</Text>
</Link>
<Link to="/topics" underlayColor="#f0f4f7" style={styles.navItem}>
<Text>Topics</Text>
</Link>
</View>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/topics" component={Topics} />
</View>
</NativeRouter>
);
}
const styles = StyleSheet.create({
container: {
marginTop: 25,
padding: 10
},
header: {
fontSize: 20
},
nav: {
flexDirection: "row",
justifyContent: "space-around"
},
navItem: {
flex: 1,
alignItems: "center",
padding: 10
},
subNavItem: {
padding: 5
},
topic: {
textAlign: "center",
fontSize: 15
}
});
export default App;