Skip to content

Commit e0e1909

Browse files
author
Carlos Rufo Jimenez
committed
4.3-end-routing-v2.1
1 parent 9ae7455 commit e0e1909

File tree

6 files changed

+112
-22
lines changed

6 files changed

+112
-22
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"react": "^16.2.0",
1010
"react-apollo": "^2.1.0-beta.3",
1111
"react-dom": "^16.2.0",
12+
"react-router": "^4.2.0",
13+
"react-router-dom": "^4.2.2",
1214
"react-scripts": "1.1.1"
1315
},
1416
"scripts": {

src/components/App.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
import React, { Component } from 'react'
2+
import LinkList from './LinkList'
23
import CreateLink from './CreateLink'
4+
import Header from './Header'
5+
import { Switch, Route } from 'react-router-dom'
36

47
class App extends Component {
58
render() {
6-
return <CreateLink />;
9+
return (
10+
<div className="center w85">
11+
<Header />
12+
<div className="ph3 pv1 background-gray">
13+
<Switch>
14+
<Route exact path="/" component={LinkList} />
15+
<Route exact path="/create" component={CreateLink} />
16+
</Switch>
17+
</div>
18+
</div>
19+
)
720
}
821
}
922

src/components/CreateLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class CreateLink extends Component {
4242
/>
4343
</div>
4444
<Mutation mutation={POST_MUTATION} variables={{ description, url }}>
45-
{postMutation => <button onClick={postMutation}>Submit</button>}
45+
{postMutation => <button onClick={() => postMutation() && this.props.history.push('/')}>Submit</button>}
4646
</Mutation>
4747
</div>
4848
)

src/components/Header.js

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

src/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ 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'
12+
1113

1214
// 2
1315
const httpLink = new HttpLink({ uri: 'http://localhost:4000' })
@@ -20,9 +22,11 @@ const client = new ApolloClient({
2022

2123
// 4
2224
ReactDOM.render(
23-
<ApolloProvider client={client}>
24-
<App />
25-
</ApolloProvider>
25+
<BrowserRouter>
26+
<ApolloProvider client={client}>
27+
<App />
28+
</ApolloProvider>
29+
</BrowserRouter>
2630
, document.getElementById('root')
2731
)
2832
registerServiceWorker()

yarn.lock

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ acorn@^4.0.3, acorn@^4.0.4:
5555
version "4.0.13"
5656
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
5757

58-
acorn@^5.0.0, acorn@^5.4.0:
58+
acorn@^5.0.0, acorn@^5.5.0:
5959
version "5.5.0"
6060
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.5.0.tgz#1abb587fbf051f94e3de20e6b26ef910b1828298"
6161

@@ -88,8 +88,8 @@ ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0:
8888
json-schema-traverse "^0.3.0"
8989

9090
ajv@^6.0.1:
91-
version "6.2.0"
92-
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.2.0.tgz#afac295bbaa0152449e522742e4547c1ae9328d2"
91+
version "6.2.1"
92+
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.2.1.tgz#28a6abc493a2abe0fb4c8507acaedb43fa550671"
9393
dependencies:
9494
fast-deep-equal "^1.0.0"
9595
fast-json-stable-stringify "^2.0.0"
@@ -2488,10 +2488,10 @@ [email protected]:
24882488
text-table "~0.2.0"
24892489

24902490
espree@^3.5.1:
2491-
version "3.5.3"
2492-
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.3.tgz#931e0af64e7fbbed26b050a29daad1fc64799fa6"
2491+
version "3.5.4"
2492+
resolved "https://registry.yarnpkg.com/espree/-/espree-3.5.4.tgz#b0f447187c8a8bed944b815a660bddf5deb5d1a7"
24932493
dependencies:
2494-
acorn "^5.4.0"
2494+
acorn "^5.5.0"
24952495
acorn-jsx "^3.0.0"
24962496

24972497
esprima@^2.6.0:
@@ -3258,6 +3258,16 @@ [email protected]:
32583258
version "1.1.1"
32593259
resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd"
32603260

3261+
history@^4.7.2:
3262+
version "4.7.2"
3263+
resolved "https://registry.yarnpkg.com/history/-/history-4.7.2.tgz#22b5c7f31633c5b8021c7f4a8a954ac139ee8d5b"
3264+
dependencies:
3265+
invariant "^2.2.1"
3266+
loose-envify "^1.2.0"
3267+
resolve-pathname "^2.2.0"
3268+
value-equal "^0.4.0"
3269+
warning "^3.0.0"
3270+
32613271
hmac-drbg@^1.0.0:
32623272
version "1.0.1"
32633273
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@@ -3274,7 +3284,7 @@ [email protected]:
32743284
version "4.2.1"
32753285
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.1.tgz#9634502aa12c445dd5a7c5734b572bb8738aacbb"
32763286

3277-
hoist-non-react-statics@^2.3.1:
3287+
hoist-non-react-statics@^2.3.0, hoist-non-react-statics@^2.3.1:
32783288
version "2.5.0"
32793289
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40"
32803290

@@ -3319,8 +3329,8 @@ html-entities@^1.2.0:
33193329
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f"
33203330

33213331
html-minifier@^3.2.3:
3322-
version "3.5.9"
3323-
resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-3.5.9.tgz#74424014b872598d4bb0e20ac420926ec61024b6"
3332+
version "3.5.10"
3333+
resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-3.5.10.tgz#8522c772c388db81aa5c26f62033302d906ea1c7"
33243334
dependencies:
33253335
camel-case "3.0.x"
33263336
clean-css "4.1.x"
@@ -3503,7 +3513,7 @@ interpret@^1.0.0:
35033513
version "1.1.0"
35043514
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.1.0.tgz#7ed1b1410c6a0e0f78cf95d3b8440c63f78b8614"
35053515

3506-
invariant@^2.2.2:
3516+
invariant@^2.2.1, invariant@^2.2.2:
35073517
version "2.2.3"
35083518
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.3.tgz#1a827dfde7dcbd7c323f0ca826be8fa7c5e9d688"
35093519
dependencies:
@@ -4392,7 +4402,7 @@ longest@^1.0.1:
43924402
version "1.0.1"
43934403
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
43944404

4395-
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
4405+
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1:
43964406
version "1.3.1"
43974407
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848"
43984408
dependencies:
@@ -5069,7 +5079,7 @@ [email protected]:
50695079
version "0.1.7"
50705080
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
50715081

5072-
path-to-regexp@^1.0.1:
5082+
path-to-regexp@^1.0.1, path-to-regexp@^1.7.0:
50735083
version "1.7.0"
50745084
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.7.0.tgz#59fde0f435badacba103a84e9d3bc64e96b9937d"
50755085
dependencies:
@@ -5495,7 +5505,7 @@ promise@^7.1.1:
54955505
dependencies:
54965506
asap "~2.0.3"
54975507

5498-
prop-types@^15.5.10, prop-types@^15.6.0:
5508+
prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.6.0:
54995509
version "15.6.1"
55005510
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.1.tgz#36644453564255ddda391191fb3a125cbdf654ca"
55015511
dependencies:
@@ -5665,6 +5675,29 @@ react-error-overlay@^4.0.0:
56655675
version "4.0.0"
56665676
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-4.0.0.tgz#d198408a85b4070937a98667f500c832f86bd5d4"
56675677

5678+
react-router-dom@^4.2.2:
5679+
version "4.2.2"
5680+
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-4.2.2.tgz#c8a81df3adc58bba8a76782e946cbd4eae649b8d"
5681+
dependencies:
5682+
history "^4.7.2"
5683+
invariant "^2.2.2"
5684+
loose-envify "^1.3.1"
5685+
prop-types "^15.5.4"
5686+
react-router "^4.2.0"
5687+
warning "^3.0.0"
5688+
5689+
react-router@^4.2.0:
5690+
version "4.2.0"
5691+
resolved "https://registry.yarnpkg.com/react-router/-/react-router-4.2.0.tgz#61f7b3e3770daeb24062dae3eedef1b054155986"
5692+
dependencies:
5693+
history "^4.7.2"
5694+
hoist-non-react-statics "^2.3.0"
5695+
invariant "^2.2.2"
5696+
loose-envify "^1.3.1"
5697+
path-to-regexp "^1.7.0"
5698+
prop-types "^15.5.4"
5699+
warning "^3.0.0"
5700+
56685701
56695702
version "1.1.1"
56705703
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-1.1.1.tgz#279d449f7311fed910506987a1ade014027788a8"
@@ -5758,8 +5791,8 @@ [email protected]:
57585791
string_decoder "~0.10.x"
57595792

57605793
readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2, readable-stream@^2.2.9, readable-stream@^2.3.3:
5761-
version "2.3.4"
5762-
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.4.tgz#c946c3f47fa7d8eabc0b6150f4a12f69a4574071"
5794+
version "2.3.5"
5795+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.5.tgz#b4f85003a938cbb6ecbce2a124fb1012bd1a838d"
57635796
dependencies:
57645797
core-util-is "~1.0.0"
57655798
inherits "~2.0.3"
@@ -6003,6 +6036,10 @@ resolve-from@^3.0.0:
60036036
version "3.0.0"
60046037
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
60056038

6039+
resolve-pathname@^2.2.0:
6040+
version "2.2.0"
6041+
resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-2.2.0.tgz#7e9ae21ed815fd63ab189adeee64dc831eefa879"
6042+
60066043
resolve-url@^0.2.1:
60076044
version "0.2.1"
60086045
resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"
@@ -6782,8 +6819,8 @@ ua-parser-js@^0.7.9:
67826819
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.17.tgz#e9ec5f9498b9ec910e7ae3ac626a805c4d09ecac"
67836820

67846821
[email protected], uglify-js@^3.0.13:
6785-
version "3.3.12"
6786-
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.3.12.tgz#efd87c16a1f4c674a8a5ede571001ef634dcc883"
6822+
version "3.3.13"
6823+
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.3.13.tgz#8a1a89eeb16e2d6a66b0db2b04cb871af3c669cf"
67876824
dependencies:
67886825
commander "~2.14.1"
67896826
source-map "~0.6.1"
@@ -6971,6 +7008,10 @@ validate-npm-package-license@^3.0.1:
69717008
spdx-correct "^3.0.0"
69727009
spdx-expression-parse "^3.0.0"
69737010

7011+
value-equal@^0.4.0:
7012+
version "0.4.0"
7013+
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-0.4.0.tgz#c5bdd2f54ee093c04839d71ce2e4758a6890abc7"
7014+
69747015
vary@~1.1.2:
69757016
version "1.1.2"
69767017
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
@@ -6999,6 +7040,12 @@ walker@~1.0.5:
69997040
dependencies:
70007041
makeerror "1.0.x"
70017042

7043+
warning@^3.0.0:
7044+
version "3.0.0"
7045+
resolved "https://registry.yarnpkg.com/warning/-/warning-3.0.0.tgz#32e5377cb572de4ab04753bdf8821c01ed605b7c"
7046+
dependencies:
7047+
loose-envify "^1.0.0"
7048+
70027049
watch@~0.10.0:
70037050
version "0.10.0"
70047051
resolved "https://registry.yarnpkg.com/watch/-/watch-0.10.0.tgz#77798b2da0f9910d595f1ace5b0c2258521f21dc"

0 commit comments

Comments
 (0)