我在使用 React 时遇到了一个错误。懒惰然后404显示在另一条路线上。
import React, { lazy, Suspense } from "react";
import { Route, Switch } from "react-router-dom";
import "./styles.css";
const HomePage = lazy(() => import("./homepage"));
const ContactPage = lazy(() => import("./contact"));
const Page404 = lazy(() => import("./notfound"));
export default function App() {
return (
<div className="App">
<Switch>
<Suspense fallback={<h1>Loading ...</h1>}>
<Route exact path="/" component={HomePage} />
<Route exact path="/contact" component={ContactPage} />
<Route component={Page404} />
</Suspense>
</Switch>
</div>
);
}
链接代码在底部。请帮我 :(