Every time when I use react router dom in my react app it get stucks on switch export
ERROR in ./src/App.js 19:39-45 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_useRouteId, UNSAFE_useScrollRestoration,
createBrowserRouter, createHashRouter, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, createSearchParams,
defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath,
unstable_HistoryRouter, unstable_useBlocker, unstable_usePrompt, useActionData, useAsyncError, useAsyncValue, useBeforeUnload, useFetcher, useFetchers, useFormAction, useHref, useInRouterContext,
useLinkClickHandler, useLoaderData, useLocation, useMatch, useMatches,
useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext,
useParams, useResolvedPath, useRevalidator, useRouteError,
useRouteLoaderData, useRoutes, useSearchParams, useSubmit)
I tried alot but nothing found
2
Answers
check your package.json, you use react-routerV6 instead react-routerV5 who let use Switch.So you can change pckg or use Routes.
According to this question "Switch" was replaced by "Routes" in react-router-dom since v6. You need to change your imports from
import { Switch } from "react-router-dom";
toimport { Routes } from "react-router-dom";