【发布时间】:2021-02-10 09:20:24
【问题描述】:
我正在研究本教程中的口袋妖怪应用列表:https://www.youtube.com/watch?v=XehSJF85F38&t=5904s
但是我有问题,由于某种原因我的路线不起作用,我做了所有的事情,就像在教程中一样。 这是我的代码:
function App() {
return (
<Router>
<div className="App">
<NavBar />
<div className="container">
<Switch>
<Route exact path="/"></Route>
<Route exact path="pokemon/:pokemonIndex" component={Pokemon} />
</Switch>
<Body />
</div>
</div>
</Router>
);
}
我在另一个组件中调用它:
render() {
return (
<div className="col-md-4 col-sm-6 mb-3">
<Link to={`pokemon/${this.state.pokemonIndex}`} className="cardLink">
<div className="card cardeffect">
<h5 className="card-header">
{this.state.pokemonIndex}. {this.state.pokemonName.toUpperCase()}
</h5>
{this.state.imageLoading ? (
<img
src={loading}
style={{ width: "6em", height: "6em" }}
className="card-img-top mx-auto mt-2"
/>
) : null}
<div className="card-body mx-auto">
<Sprite
className="card-image-top mx-auto mt-2"
onLoad={() => this.setState({ imageLoading: false })}
onError={() => this.setState({ request: true })}
src={this.state.imageUrl}
style={
this.state.tooManyRequest
? { display: "none" }
: this.state.imageLoading
? { display: "none" }
: { display: "block" }
}
></Sprite>
</div>
</div>
</Link>
</div>
);
}
但是当我点击任何卡片时,URL 会发生变化,但仅此而已。
【问题讨论】:
标签: reactjs rxjs react-router