The Layout page is not showing up if the home page does and vice versa i tried changing the version of the react router dom to 5 but it is still not working I also used router insted of route it is still not working.
//App.js file
import React from "react";
import { Route,Routes } from "react-router-dom";
import Layout from './components/Layout';
import Home from './components/Home';
import './App.scss';
function App() {
return (
<Routes>
<>
<Route exact path='/' Component={Layout} />
<Route exact path='/' component={Home} />
</>
</Routes>
);
}
export default App;
i also tried restarting the application and i also tried deleteing and reinstalling the react-router-dom and node_modules.
2
Answers
The paths you specified for both routes are the same.
Use a different route for one component.
And also if you are using react-router-dom version 6, pass component to element prop.
You are using uppercase
Component
instead of lowercasecomponent
in yourRoute
components.Change them to lowercase
component
:In React Router v6, the
Route
components are not used anymore. Instead, you use theRoutes
component to define your route configuration. The individual routes are defined using theRoute
element insideRoutes
.Here’s how you should configure your routes:
It seems like you want to show the
Layout
component when the home page is accessed, and theHome
component when the/home
route is accessed. Therefore, you should differentiate the paths for the two components:Make sure that the
Layout
andHome
components are correctly imported and that their paths are set up correctly in your project structure.Remember to update your
Link
components accordingly if you are using them to navigate between routes.