首页 > 解决方案 > 无法通过 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>
  );
}

标签: javascriptreactjs

解决方案


推荐阅读