Skip to content

Commit 9a4d9f5

Browse files
author
Carlos Rufo Jimenez
committed
4.4-end-routing-v2.1
1 parent 7c9932c commit 9a4d9f5

File tree

4 files changed

+46
-7
lines changed

4 files changed

+46
-7
lines changed

src/components/App.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import React from 'react'
22
import LinkList from './LinkList'
33
import CreateLink from './CreateLink'
4+
import Header from './Header'
5+
import { Switch, Route } from 'react-router-dom'
46

5-
export default () => <CreateLink />
7+
export default () => (
8+
<div className="center w85">
9+
<Header />
10+
<div className="ph3 pv1 background-gray">
11+
<Switch>
12+
<Route exact path="/" component={LinkList} />
13+
<Route exact path="/create" component={CreateLink} />
14+
</Switch>
15+
</div>
16+
</div>
17+
)

src/components/CreateLink.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class CreateLink extends Component {
3939
placeholder="The URL for the link"
4040
/>
4141
</div>
42-
<Mutation mutation={POST_MUTATION} variables={{ description, url }}>
42+
<Mutation
43+
mutation={POST_MUTATION}
44+
variables={{ description, url }}
45+
onCompleted={() => this.props.history.push('/')}
46+
>
4347
{postMutation => <button onClick={postMutation}>Submit</button>}
4448
</Mutation>
4549
</div>

src/components/Header.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { Link } from 'react-router-dom'
3+
import { withRouter } from 'react-router'
4+
5+
const Header = () => (
6+
<div className="flex pa1 justify-between nowrap orange">
7+
<div className="flex flex-fixed black">
8+
<div className="fw7 mr1">Hacker News</div>
9+
<Link to="/" className="ml1 no-underline black">
10+
new
11+
</Link>
12+
<div className="ml1">|</div>
13+
<Link to="/create" className="ml1 no-underline black">
14+
submit
15+
</Link>
16+
</div>
17+
</div>
18+
)
19+
20+
export default withRouter(Header)

src/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ApolloProvider } from 'react-apollo'
88
import { ApolloClient } from 'apollo-client'
99
import { HttpLink } from 'apollo-link-http'
1010
import { InMemoryCache } from 'apollo-cache-inmemory'
11+
import { BrowserRouter } from 'react-router-dom'
1112

1213
// 2
1314
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
@@ -20,9 +21,11 @@ const client = new ApolloClient({
2021

2122
// 4
2223
ReactDOM.render(
23-
<ApolloProvider client={client}>
24-
<App />
25-
</ApolloProvider>
26-
, document.getElementById('root')
24+
<BrowserRouter>
25+
<ApolloProvider client={client}>
26+
<App />
27+
</ApolloProvider>
28+
</BrowserRouter>,
29+
document.getElementById('root')
2730
)
28-
registerServiceWorker()
31+
registerServiceWorker()

0 commit comments

Comments
 (0)