I solved this problem by changing:
import {Route, Switch} from "react-router";
to
import {Route, Switch} from "react-router-dom";
just add -dom.
More Related Contents:
- React : difference between and
- How to create a protected route?
- React-router-v6 access a url parameter
- React Router v4 renders multiple routes
- How to pass params into link using React router v6?
- react-router-dom v6 useNavigate passing value to another component
- Detect Route Change with react-router
- Simple Conditional Routing in Reactjs
- Cannot read property ‘history’ of undefined (useHistory hook of React Router 5)
- useNavigate() may be used only in the context of a component
- React Router Dom v6 shows active for index as well as other subroutes
- React – TypeError: Cannot read properties of undefined (reading ‘params’)
- Error: useHref() may be used only in the context of a component. It works when I directly put the url as localhost:3000/experiences
- react app showing empty page when redirecting on production build
- React App goes blank after importing React-Router-Dom
- React Router 4 Nested Routes not rendering
- Children won’t render when using a layout in ReactJS
- How to go back to previous route in react-router-dom v6
- React Router V6 – Error: useRoutes() may be used only in the context of a component
- How to push to History in React Router v4?
- How to pass params with history.push/Link/Redirect in react-router v4?
- How to get history on react-router v4?
- Detecting user leaving page with react-router
- React Router v4 – How to get current route?
- You should not use outside a
- react router v4 default page(not found page)
- How to use Private route in react-router-dom@v6
- Difference in the navigation (React Router v6)
- react router v6 No routes matched location
- Passing values through React-Router v4