24
loading...
This website collects cookies to deliver better user experience
Error: A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.
import React from 'react';
import { Container } from 'react-bootstrap';
import { BrowserRouter as Router, Route} from 'react-router-dom'
import Footer from './components/Footer';
import Header from './components/Header'
import HomeScreen from './screens/HomeScreen';
import ProductScreen from './screens/ProductScreen';
function App() {
return (
<Router>
<Header />
<main className='py-3'>
<Container>
<Route path='/' component={HomeScreen} exact />
<Route path='/product:id' component={ProductScreen} />
</Container>
</main>
<Footer />
</Router>
);
}
export default App;
<Route />
components in a <Routes />
component (it replaces the <Switch />
component).<Route path='/' component={HomeScreen} exact/>
<Route path='/product:id' component={ProductScreen} />
<Route path='/' element={<HomeScreen />} />
<Route path='product/:id' element={<ProductScreen />} />
element
instead of component
, and instead of just typing the name of the component the route is pointing to, you write it as if you are rendering it (like <ProductScreen />
).exact
property again because Route paths match exactly by default.useParams
from 'react-router-dom'