Skip to content

Commit 58121b4

Browse files
committed
Routing
1 parent f7a3130 commit 58121b4

File tree

6 files changed

+134
-11
lines changed

6 files changed

+134
-11
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"react": "^16.13.1",
1212
"react-apollo": "^3.1.5",
1313
"react-dom": "^16.13.1",
14+
"react-router": "^5.1.2",
15+
"react-router-dom": "^5.1.2",
1416
"react-scripts": "3.4.1"
1517
},
1618
"scripts": {

src/components/App.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import React, { Component } 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

57
class App extends Component {
68
render() {
79
return (
8-
<div>
9-
<LinkList />
10-
<CreateLink></CreateLink>
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>
1118
</div>
1219
)
1320
}

src/components/CreateLink.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CreateLink extends Component {
3838
placeholder="The URL for the link"
3939
/>
4040
</div>
41-
<Mutation mutation={POST_MUTATION} variables={{ description, url }}>
41+
<Mutation mutation={POST_MUTATION} variables={{ description, url }} onCompleted={() => this.props.history.push('/')}>
4242
{postMutation => <button onClick={postMutation}>Submit</button>}
4343
</Mutation>
4444
</div>

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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { ApolloClient } from 'apollo-client'
77
import { createHttpLink } from 'apollo-link-http'
88
import { InMemoryCache } from 'apollo-cache-inmemory'
99
import * as serviceWorker from './serviceWorker';
10+
import { BrowserRouter } from 'react-router-dom'
1011

1112
const httpLink = createHttpLink({
1213
uri: 'http://localhost:4000'
@@ -18,9 +19,11 @@ const client = new ApolloClient({
1819
})
1920

2021
ReactDOM.render(
21-
<ApolloProvider client={client}>
22-
<App />
23-
</ApolloProvider>,
22+
<BrowserRouter>
23+
<ApolloProvider client={client}>
24+
<App />
25+
</ApolloProvider>
26+
</BrowserRouter>,
2427
document.getElementById('root')
2528
);
2629

yarn.lock

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@
10051005
dependencies:
10061006
regenerator-runtime "^0.13.4"
10071007

1008-
"@babel/runtime@^7.5.1", "@babel/runtime@^7.7.4":
1008+
"@babel/runtime@^7.1.2", "@babel/runtime@^7.4.0", "@babel/runtime@^7.5.1", "@babel/runtime@^7.7.4":
10091009
version "7.9.6"
10101010
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.9.6.tgz#a9102eb5cadedf3f31d08a9ecf294af7827ea29f"
10111011
integrity sha512-64AF1xY3OAkFHqOb9s4jpgk1Mm5vDZ4L3acHvAml+53nO1XbXLuDodsVpO4OIUsmemlUHMxNdYMNJmsvOwLrvQ==
@@ -4970,6 +4970,11 @@ growly@^1.3.0:
49704970
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
49714971
integrity sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=
49724972

4973+
gud@^1.0.0:
4974+
version "1.0.0"
4975+
resolved "https://registry.yarnpkg.com/gud/-/gud-1.0.0.tgz#a489581b17e6a70beca9abe3ae57de7a499852c0"
4976+
integrity sha512-zGEOVKFM5sVPPrYs7J5/hYEw2Pof8KCyOwyhG8sAF26mCAeUFAcYPu1mwB7hhpIP29zOIBaDqwuHdLp0jvZXjw==
4977+
49734978
gzip-size@5.1.1:
49744979
version "5.1.1"
49754980
resolved "https://registry.yarnpkg.com/gzip-size/-/gzip-size-5.1.1.tgz#cb9bee692f87c0612b232840a873904e4c135274"
@@ -5087,6 +5092,18 @@ hex-color-regex@^1.1.0:
50875092
resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e"
50885093
integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ==
50895094

5095+
history@^4.9.0:
5096+
version "4.10.1"
5097+
resolved "https://registry.yarnpkg.com/history/-/history-4.10.1.tgz#33371a65e3a83b267434e2b3f3b1b4c58aad4cf3"
5098+
integrity sha512-36nwAD620w12kuzPAsyINPWJqlNbij+hpK1k9XRloDtym8mxzGYl2c17LnV6IAGB2Dmg4tEa7G7DlawS0+qjew==
5099+
dependencies:
5100+
"@babel/runtime" "^7.1.2"
5101+
loose-envify "^1.2.0"
5102+
resolve-pathname "^3.0.0"
5103+
tiny-invariant "^1.0.2"
5104+
tiny-warning "^1.0.0"
5105+
value-equal "^1.0.1"
5106+
50905107
hmac-drbg@^1.0.0:
50915108
version "1.0.1"
50925109
resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1"
@@ -5096,7 +5113,7 @@ hmac-drbg@^1.0.0:
50965113
minimalistic-assert "^1.0.0"
50975114
minimalistic-crypto-utils "^1.0.1"
50985115

5099-
hoist-non-react-statics@^3.3.0:
5116+
hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0:
51005117
version "3.3.2"
51015118
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
51025119
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
@@ -5782,6 +5799,11 @@ is-wsl@^2.1.1:
57825799
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.1.1.tgz#4a1c152d429df3d441669498e2486d3596ebaf1d"
57835800
integrity sha512-umZHcSrwlDHo2TGMXv0DZ8dIUGunZ2Iv68YZnrmCiBPkZ4aaOhtv7pXJKeki9k3qJ3RJr0cDyitcl5wEH3AYog==
57845801

5802+
isarray@0.0.1:
5803+
version "0.0.1"
5804+
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
5805+
integrity sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=
5806+
57855807
isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0:
57865808
version "1.0.0"
57875809
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
@@ -6634,7 +6656,7 @@ loglevel@^1.6.6:
66346656
resolved "https://registry.yarnpkg.com/loglevel/-/loglevel-1.6.7.tgz#b3e034233188c68b889f5b862415306f565e2c56"
66356657
integrity sha512-cY2eLFrQSAfVPhCgH1s7JI73tMbg9YC3v3+ZHVW67sBS7UxWzNEk/ZBbSfLykBWHp33dqqtOv82gjhKEi81T/A==
66366658

6637-
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
6659+
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0:
66386660
version "1.4.0"
66396661
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
66406662
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
@@ -6838,6 +6860,15 @@ min-indent@^1.0.0:
68386860
resolved "https://registry.yarnpkg.com/min-indent/-/min-indent-1.0.0.tgz#cfc45c37e9ec0d8f0a0ec3dd4ef7f7c3abe39256"
68396861
integrity sha1-z8RcN+nsDY8KDsPdTvf3w6vjklY=
68406862

6863+
mini-create-react-context@^0.3.0:
6864+
version "0.3.2"
6865+
resolved "https://registry.yarnpkg.com/mini-create-react-context/-/mini-create-react-context-0.3.2.tgz#79fc598f283dd623da8e088b05db8cddab250189"
6866+
integrity sha512-2v+OeetEyliMt5VHMXsBhABoJ0/M4RCe7fatd/fBy6SMiKazUSEt3gxxypfnk2SHMkdBYvorHRoQxuGoiwbzAw==
6867+
dependencies:
6868+
"@babel/runtime" "^7.4.0"
6869+
gud "^1.0.0"
6870+
tiny-warning "^1.0.2"
6871+
68416872
mini-css-extract-plugin@0.9.0:
68426873
version "0.9.0"
68436874
resolved "https://registry.yarnpkg.com/mini-css-extract-plugin/-/mini-css-extract-plugin-0.9.0.tgz#47f2cf07aa165ab35733b1fc97d4c46c0564339e"
@@ -7629,6 +7660,13 @@ path-to-regexp@0.1.7:
76297660
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
76307661
integrity sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=
76317662

7663+
path-to-regexp@^1.7.0:
7664+
version "1.8.0"
7665+
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-1.8.0.tgz#887b3ba9d84393e87a0a0b9f4cb756198b53548a"
7666+
integrity sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==
7667+
dependencies:
7668+
isarray "0.0.1"
7669+
76327670
path-type@^2.0.0:
76337671
version "2.0.0"
76347672
resolved "https://registry.yarnpkg.com/path-type/-/path-type-2.0.0.tgz#f012ccb8415b7096fc2daa1054c3d72389594c73"
@@ -8730,11 +8768,40 @@ react-error-overlay@^6.0.7:
87308768
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.7.tgz#1dcfb459ab671d53f660a991513cb2f0a0553108"
87318769
integrity sha512-TAv1KJFh3RhqxNvhzxj6LeT5NWklP6rDr2a0jaTfsZ5wSZWHOGeqQyejUp3xxLfPt2UpyJEcVQB/zyPcmonNFA==
87328770

8733-
react-is@^16.12.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4:
8771+
react-is@^16.12.0, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4:
87348772
version "16.13.1"
87358773
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
87368774
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
87378775

8776+
react-router-dom@^5.1.2:
8777+
version "5.1.2"
8778+
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-5.1.2.tgz#06701b834352f44d37fbb6311f870f84c76b9c18"
8779+
integrity sha512-7BPHAaIwWpZS074UKaw1FjVdZBSVWEk8IuDXdB+OkLb8vd/WRQIpA4ag9WQk61aEfQs47wHyjWUoUGGZxpQXew==
8780+
dependencies:
8781+
"@babel/runtime" "^7.1.2"
8782+
history "^4.9.0"
8783+
loose-envify "^1.3.1"
8784+
prop-types "^15.6.2"
8785+
react-router "5.1.2"
8786+
tiny-invariant "^1.0.2"
8787+
tiny-warning "^1.0.0"
8788+
8789+
react-router@5.1.2, react-router@^5.1.2:
8790+
version "5.1.2"
8791+
resolved "https://registry.yarnpkg.com/react-router/-/react-router-5.1.2.tgz#6ea51d789cb36a6be1ba5f7c0d48dd9e817d3418"
8792+
integrity sha512-yjEuMFy1ONK246B+rsa0cUam5OeAQ8pyclRDgpxuSCrAlJ1qN9uZ5IgyKC7gQg0w8OM50NXHEegPh/ks9YuR2A==
8793+
dependencies:
8794+
"@babel/runtime" "^7.1.2"
8795+
history "^4.9.0"
8796+
hoist-non-react-statics "^3.1.0"
8797+
loose-envify "^1.3.1"
8798+
mini-create-react-context "^0.3.0"
8799+
path-to-regexp "^1.7.0"
8800+
prop-types "^15.6.2"
8801+
react-is "^16.6.0"
8802+
tiny-invariant "^1.0.2"
8803+
tiny-warning "^1.0.0"
8804+
87388805
react-scripts@3.4.1:
87398806
version "3.4.1"
87408807
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-3.4.1.tgz#f551298b5c71985cc491b9acf3c8e8c0ae3ada0a"
@@ -9093,6 +9160,11 @@ resolve-from@^4.0.0:
90939160
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
90949161
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
90959162

9163+
resolve-pathname@^3.0.0:
9164+
version "3.0.0"
9165+
resolved "https://registry.yarnpkg.com/resolve-pathname/-/resolve-pathname-3.0.0.tgz#99d02224d3cf263689becbb393bc560313025dcd"
9166+
integrity sha512-C7rARubxI8bXFNB/hqcp/4iUeIXJhJZvFPFPiSPRnhU5UPxzMFIl+2E6yY6c4k9giDJAhtV+enfA+G89N6Csng==
9167+
90969168
resolve-url-loader@3.1.1:
90979169
version "3.1.1"
90989170
resolved "https://registry.yarnpkg.com/resolve-url-loader/-/resolve-url-loader-3.1.1.tgz#28931895fa1eab9be0647d3b2958c100ae3c0bf0"
@@ -10117,6 +10189,16 @@ timsort@^0.3.0:
1011710189
resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4"
1011810190
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=
1011910191

10192+
tiny-invariant@^1.0.2:
10193+
version "1.1.0"
10194+
resolved "https://registry.yarnpkg.com/tiny-invariant/-/tiny-invariant-1.1.0.tgz#634c5f8efdc27714b7f386c35e6760991d230875"
10195+
integrity sha512-ytxQvrb1cPc9WBEI/HSeYYoGD0kWnGEOR8RY6KomWLBVhqz0RgTwVO9dLrGz7dC+nN9llyI7OKAgRq8Vq4ZBSw==
10196+
10197+
tiny-warning@^1.0.0, tiny-warning@^1.0.2:
10198+
version "1.0.3"
10199+
resolved "https://registry.yarnpkg.com/tiny-warning/-/tiny-warning-1.0.3.tgz#94a30db453df4c643d0fd566060d60a875d84754"
10200+
integrity sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==
10201+
1012010202
tmp@^0.0.33:
1012110203
version "0.0.33"
1012210204
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
@@ -10469,6 +10551,11 @@ validate-npm-package-license@^3.0.1:
1046910551
spdx-correct "^3.0.0"
1047010552
spdx-expression-parse "^3.0.0"
1047110553

10554+
value-equal@^1.0.1:
10555+
version "1.0.1"
10556+
resolved "https://registry.yarnpkg.com/value-equal/-/value-equal-1.0.1.tgz#1e0b794c734c5c0cade179c437d356d931a34d6c"
10557+
integrity sha512-NOJ6JZCAWr0zlxZt+xqCHNTEKOsrks2HQd4MqhP1qy4z1SkbEP467eNx6TgDKXMvUOb+OENfJCZwM+16n7fRfw==
10558+
1047210559
vary@~1.1.2:
1047310560
version "1.1.2"
1047410561
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"

0 commit comments

Comments
 (0)