Skip to content

Commit e7dc5ce

Browse files
committed
use react router link
1 parent 4e89a7b commit e7dc5ce

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/App.js

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const RabbitHolePage = withRouter(
8080
super(props);
8181
this.state = {
8282
wikiData: {},
83-
firstPageTitle: "",
83+
firstPageTitle: '',
8484
};
8585
}
8686

@@ -141,7 +141,9 @@ const RabbitHolePage = withRouter(
141141
// 3. /wiki/Mammal -> /#/?wiki=Pet_door|Dog|Mammal
142142
// TODO Handle if URL is too long, show message like
143143
// "you've been in the rabbit hole too long"
144-
`/#/?wiki=${wikiValue ? `${wikiValue}` : `${this.state.firstPageTitle}`}|`
144+
`/#/?wiki=${
145+
wikiValue ? `${wikiValue}` : `${this.state.firstPageTitle}`
146+
}|`
145147
);
146148
}
147149

@@ -163,26 +165,20 @@ const RabbitHolePage = withRouter(
163165
}
164166

165167
startNewRabbithole() {
166-
fetch(
167-
`https://en.wikipedia.org/api/rest_v1/page/random/title`,
168-
{
169-
headers: {
170-
'Content-Type': 'application/json',
171-
},
172-
}
173-
)
174-
.then((resp) => resp.json())
175-
.then((randomTitleData) => {
176-
const randomPageTitle = randomTitleData.items[0].title;
177-
console.log('TITLE FETCH resp', randomPageTitle);
178-
this.setState({ firstPageTitle: randomPageTitle });
179-
180-
this.fetchPage(randomPageTitle);
181-
182-
});
183-
}
184-
168+
fetch(`https://en.wikipedia.org/api/rest_v1/page/random/title`, {
169+
headers: {
170+
'Content-Type': 'application/json',
171+
},
172+
})
173+
.then((resp) => resp.json())
174+
.then((randomTitleData) => {
175+
const randomPageTitle = randomTitleData.items[0].title;
176+
console.log('TITLE FETCH resp', randomPageTitle);
177+
this.setState({ firstPageTitle: randomPageTitle });
185178

179+
this.fetchPage(randomPageTitle);
180+
});
181+
}
186182

187183
render() {
188184
var rabbitHolePath = [];
@@ -196,17 +192,15 @@ const RabbitHolePage = withRouter(
196192

197193
return (
198194
<div>
199-
<a href="/#/" onClick={() => this.startNewRabbithole()}>
195+
<Link to="/" onClick={() => this.startNewRabbithole()}>
200196
START OVER
201-
</a>
197+
</Link>
202198

203199
<ul>
204200
{rabbitHolePath.map((pageTitle, index) => (
205201
<li key={index}>{pageTitle}</li>
206-
)
207-
)}
202+
))}
208203
</ul>
209-
210204

211205
{this.state.wikiData.lead &&
212206
this.state.wikiData.lead.sections &&

0 commit comments

Comments
 (0)