react:スイッチの基本的な使い方、ページ構成コンポーネントが見つかりません
V 5の場合はSWICHを使用し、V 6の場合はRoutesに変更します.
👉 v5
デフォルトのアプリケーション.jsでルーティングを構成する場合、swichで包むと、ルーティング機能をより実用的に使用できます.
ルートを囲む構造を用いて,アクセス順を上から下へ行う.
見つからないページに警告したい場合は、下部にpathのないcomponentを設定するだけです.
👉 v5
<Switch>
<Route path="/" exact element={Home} />
<Route path="/about" exact element={About} />
</Switch>
👉 v6<Routes>
<Route path="/" exact element={<Home />} />
<Route path="/about" exact element={<About />} />
</Routes>
個人的にはV 5の直感性も大好きです.デフォルトのアプリケーション.jsでルーティングを構成する場合、swichで包むと、ルーティング機能をより実用的に使用できます.
スイッチ
ルートを囲む構造を用いて,アクセス順を上から下へ行う.
見つからないページに警告したい場合は、下部にpathのないcomponentを設定するだけです.
import { BrowserRouter, Route, Switch } from "react-router-dom";
import About from "./pages/About";
import Home from "./pages/Home";
import Profile from "./pages/Profile";
import NotFound from "./pages/NotFound";
function App() {
return (
<BrowserRouter>
<Switch>
<Route path="/profile/:id" component={Profile} />
<Route path="/profile" component={Profile} />
<Route path="/about" component={About} />
<Route path="/" exact component={Home} />
<Route component={NotFound} />
</Switch>
</BrowserRouter>
);
}
export default App;
👉 設定されていないパスが表示されると、最後にルーティングされた画面が表示されます.Reference
この問題について(react:スイッチの基本的な使い方、ページ構成コンポーネントが見つかりません), 我々は、より多くの情報をここで見つけました https://velog.io/@whdms3368/React-기본기-익히기-Switch-기본-사용법-페이지를-찾을-수-없습니다-컴포넌트-구성テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol