交换机路由器在react应用程序中不工作i installed npm install react-router-dom
但还是不行
Error in ./src/App.js 12:35-41 export 'Switch'(imported as 'Switch')was not found in 'react-router-dom'(possible exports:AbortedDeferredError,Await,BrowserRouter,Form,HashRouter,Link,MemoryRouter,NavLink,Navigate,NavigationType,Outlet,Route,Router,RouterProvider,Routes,ScrollRestoration,UNSAFE_DataRouterContext,UNSAFE_DataRouterStateContext,UNSAFE_LocationContext,UNSAFE_NavigationContext,UNSAFE_RouteContext,UNSAFE_useScrollRestoration,createBrowserRouter,createHashRouter,createMemoryRouter,createPath,createRoutesFromChildren,createRoutesFromElements,createSearchParams,defer,generatePath,isRouteErrorResponse,json,matchPath,matchRoutes,parsePath,redirect,renderMatches,resolvePath,unstable_HistoryRouter,unstable_useBlocker,unstable_usePrompt,useActionData,useAsyncError,useAsyncValue,useBeforeUnload,useFetcher,useFetchers,useFormAction,useHref,useInRouterContext,useLinkClickHandler,useLoaderData,useLocation,useMatch,useMatches,useNavigation,useNavigationType,useOutlet,useOutletContext,useParams,useResolvedPath、useRevalidator、useRouteError、useRouteLoaderData、useRoutes、useSearchParams、useSubmit)
我安装了npm install react-router-dom,但它仍然不工作
1条答案
按热度按时间ee7vknir1#
关于您安装的
react-router-dom
版本信息不多,但我假设您安装的是最新版本6.10.0。在这种情况下,请参考以下答案:https://stackoverflow.com/a/69843676/17465266tl;dr是
Switch
被替换为Routes
。看看这里的例子(来自https://reactrouter.com/en/main/components/routes):