javascript - 无法通过 reactjs 中的 URL 发送状态
问题描述
我正在尝试发送状态 404,但在使用以下代码时无法发送。我正在为 react-router-dom 使用版本 5。我尝试了各种方法,但仍然没有显示正确的状态,并且每个 URL 都显示 200。
return (
<Router>
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Welcome to the Pokédex</h1>
</header>
<br />
<br />
<div className="App-body">
<h2>Information about Pokémon, Berries and Machine</h2>
<p>This website will tell you about how pokemon works.</p>
<Link className="showlink" to="/pokemon/page/0">
Pokémon
</Link>
<Link className="showlink" to="/berries/page/0">
Berries
</Link>
<Link className="showlink" to="/machines/page/0">
Machines
</Link>
<Switch>
<Route exact path="/" />
<Route
exact
path="/pokemon/page/:page"
exact
component={PokemonList}
/>
<Route
exact
path="/berries/page/:page"
exact
component={BerriesList}
/>
<Route
exact
path="/machines/page/:page"
exact
component={MachineList}
/>
<Route exact path="/pokemon/:id" exact component={Pokemon} />
<Route exact path="/berries/:id" exact component={Berries} />
<Route exact path="/machines/:id" exact component={Machines} />
<Route path="*" status={404}>
<PageNotFound />
</Route>
</Switch>
</div>
</div>
</Router>
);
}
解决方案
推荐阅读
- esapi - 未找到 EzAPI 方法
- php - PHP cURL - 代码不适用于特定 URL
- c# - Blazor 子组件 EventCallBack 没有响应
- omnet++ - 如何添加另一个 RSU 子模块?
- machine-learning - 批量大小应该如何定制?
- nginx - Trailing slash throws 404 even after nginx rewrite
- javascript - Angular closing material dialog from dialog's child component throws errors
- r - Subset of data frame by a data frame of indexes
- performance - From Websphere 6.1.35 to Websphere 8.5.5.17 - application startup impacted by filesystem scan
- python - I unable to install any package using pip with python 3.9.0 64-bit on Windows 10 64-bit