How can I fix the problem react Switch Autocomplete import from react-router-dom

Okshi hafiz

I can't use Switch from react auto import, where I'm able to auto import Router from react.

import { BrowserRouter as Router  } from 'react-router-dom';

function App() {
return (
<div>
  
  <Router>
      <Switch>

      </Switch>
  </Router>
  
  </div>
 );
}
tomerpacific

The problem you have is because you did not import the Switch component from react-router.

Per the documentation, you need to do the following:

import { Route, Switch } from "react-router";

let routes = (
  <Switch>
    <Route exact path="/">
      <Home />
    </Route>
    <Route path="/about">
      <About />
    </Route>
    <Route path="/:user">
      <User />
    </Route>
    <Route>
      <NoMatch />
    </Route>
  </Switch>
);

So in your case:

import { BrowserRouter as Router  } from 'react-router-dom';
import { Switch } from "react-router";

function App() {
return (
<div>
  
  <Router>
      <Switch>

      </Switch>
  </Router>
  
  </div>
 );
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to fix error: Attempted import error: 'Route' is not exported from 'react-router-dom'

I can't import Link attribute from react-router-dom

React Router Dom not recognizing useHistory hook, how do I fix this?

Switch' is not exported from 'react-router-dom'

Can not Import React Router Dom In Gulp Project

Usign react-router-dom, how can I access browserHistory object from outside a React component?

./src/App.js Attempted import error: 'Switch' is not exported from 'react-router-dom'

Error: ./src/App.js Attempted import error: 'Switch' is not exported from 'react-router-dom'

How to fix Reactjs admin and frontend routing with react-router-dom v6 BrowserRouter insted of Switch

How I can check with react-router-dom 6.0.2 v

How can I pass the component's name from another component's object to Route in React Router Dom?

Using react-router-dom, how can I get the list of children routes from the element?

How can i fix React admin reference input problem?

How can I fix react-redux resolve problem?

Can't render route with switch statements React router dom 5.0.0

How to upgrade from react-router to react-router-dom?

ReactJS can't import 'react-router-dom' anymore

Attempted import error: 'Outlet' is not exported from 'react-router-dom'

Attempted import error: 'useRouteMatch' is not exported from 'react-router-dom'

Attempted import error: 'PrivateRoute' is not exported from 'react-router-dom'

Attempted import error: 'useHistory' is not exported from 'react-router-dom'

Attempted import error: 'Routes' is not exported from 'react-router-dom'

Attempted import error: 'Navigate' is not exported from 'react-router-dom'

How can I replace bits or string with React component, react-router-dom Link or an anchor tag <a></a>

How to fix an import error using a Match object in React Router

How do I fix a problem where adding a new React Router path causes unexpected issues

I have a problem with React Router Dom V6 and useState

How can I pass props to a Link component from react-router-dom via Semantic UI's augmentation?

React Formik Material UI Autocomplete: How can I populate value inside of autocomplete from localStorage?

TOP Ranking

HotTag

Archive