0

This is my home component. The issue is when normally loading the home component it gets loaded, but while using router it doesn't.

 import React from 'react';
   import {BrowserRouter, Routes,Router,Route}from "react-router-dom";
    import Home from './componenets/Home/Home.js';
    
    
    export default function App() {
      return (
        
        <Router>
        <Routes>
           <Route path="/" element={<Home />} />
          
        </Routes>
    </Router>
        
    
      )

}



import React from "react";
import './Home.css'

    export default function Home()
    {
        return(
           <div className="a">
            <h1>Home</h1>
           </div>
        )
    }
isherwood
  • 58,414
  • 16
  • 114
  • 157
  • You're missing a few things outlined in [the tutorial](https://github.com/remix-run/react-router/blob/main/docs/start/tutorial.md#adding-a-router). I'd start there. – isherwood Nov 21 '22 at 15:17
  • Try and replace component with component maybe? – Marios Nov 21 '22 at 15:34
  • @Marios Thanks but it throws error –  Nov 21 '22 at 15:38
  • @isherwood Thanks for the reply but it used to work this way.However its been some time since i used react –  Nov 21 '22 at 15:38
  • @ATHULSURESH when importing you write import Home from './componenets/Home/Home.js'; Is that "componenets" folder correct? I guess it's a typo and instead you wanted 'components' – Marios Nov 21 '22 at 15:49
  • @Marios Thanks for the reply adding works now can you explain why it wasnt working earlier –  Nov 21 '22 at 16:52

1 Answers1

0

can you try this;

<BrowserRouter>
   <Routes>
      <Route path="/" element={<Home/>} />  
   </Routes>
</BrowserRouter>

If it doesn't work, can you post the react-router-dom version? There may be some differences.

  • Thanks for the reply adding works now can you explain why it wasnt working earlier – –  Nov 21 '22 at 17:05
  • https://stackoverflow.com/a/56778534/17450051 ( I'd appreciate it if you could confirm my answer was helpful :D ) – yusufakcekoce Nov 22 '22 at 07:51