forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (81 loc) · 1.97 KB
/
app.js
File metadata and controls
89 lines (81 loc) · 1.97 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
import React from 'react'
import { render } from 'react-dom'
import { createHistory, useBasename } from 'history'
import { Router, Route, Link } from 'react-router'
const history = useBasename(createHistory)({
basename: '/shared-root'
})
class App extends React.Component {
render() {
return (
<div>
<p>
This illustrates how routes can share UI w/o sharing the URL.
When routes have no path, they never match themselves but their
children can, allowing "/signin" and "/forgot-password" to both
be render in the <code>SignedOut</code> component.
</p>
<ol>
<li><Link to="/home" activeClassName="active">Home</Link></li>
<li><Link to="/signin" activeClassName="active">Sign in</Link></li>
<li><Link to="/forgot-password" activeClassName="active">Forgot Password</Link></li>
</ol>
{this.props.children}
</div>
)
}
}
class SignedIn extends React.Component {
render() {
return (
<div>
<h2>Signed In</h2>
{this.props.children}
</div>
)
}
}
class Home extends React.Component {
render() {
return (
<h3>Welcome home!</h3>
)
}
}
class SignedOut extends React.Component {
render() {
return (
<div>
<h2>Signed Out</h2>
{this.props.children}
</div>
)
}
}
class SignIn extends React.Component {
render() {
return (
<h3>Please sign in.</h3>
)
}
}
class ForgotPassword extends React.Component {
render() {
return (
<h3>Forgot your password?</h3>
)
}
}
render((
<Router history={history}>
<Route path="/" component={App}>
<Route component={SignedOut}>
<Route path="signin" component={SignIn} />
<Route path="forgot-password" component={ForgotPassword} />
</Route>
<Route component={SignedIn}>
<Route path="home" component={Home} />
</Route>
</Route>
</Router>
), document.getElementById('example'))