1

i want to make simple navbar ,i read react router documentation.i think my code is correct,but it return these error :enter image description here

my app code:

import './App.css';
import Dashboard from './component/dashboard';
import Home from './component/home';
import Navbar from './component/navbar';
import {BrowserRouter as Router,Routes,Route} from "react-router-dom"
function App() {
  return (
    <div className="App">
      <Navbar/>
      <div id="body">
      <Router >
        <Routes>
          <Route path="/"  element={<Home/>}/>
          <Route path="/dashboard"  element={<Dashboard/>}/>
        </Routes>
      </Router>
      
      </div>
    </div>
  );
}

export default App;

my navbar code :

import { NavLink } from "react-router-dom"
export default function Navbar(){


    return(<div className="App-header">
    <div id="logo">
      <p>logo</p>
      </div>
      <div id="nav_bar">
        <NavLink  to="/dashboard">dashboard</NavLink>
      </div>
      <div id="cantact_slide">
        <p>contact</p>
      </div>
</div>)
}

I installed react-router-dom: "^6.11.2",nodejs : v18.16.0

sifo
  • 33
  • 5
  • Hy, please [don't upload text, table or error message as image](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557). Edit your question to contain all the information in text form - consider to use the editor's formatting options. Also see [How to Ask](https://stackoverflow.com/help/how-to-ask) – Daxelarne May 24 '23 at 10:54
  • Search useContext and useRef in you project, find missing imports – Raphael Ben Hamo May 24 '23 at 11:04
  • In the recent versions react router dom has changed the way we define routers. Please refer this: https://reactrouter.com/en/main/upgrading/v6-data – CodeThing May 24 '23 at 11:12
  • @RaphaelBenHamo I didn't use them, ,it's a simple app, i create react-app , and i installed react router Dom, then i did the code. – sifo May 24 '23 at 11:13
  • can you share the code in Codepen? – Raphael Ben Hamo May 24 '23 at 11:17
  • @RaphaelBenHamo ,https://codepen.io/saif-eddine-rebouli/pen/NWOoexX – sifo May 24 '23 at 12:17
  • 2
    TL;DR move the `Navbar` component into the router. – Drew Reese May 24 '23 at 18:28

0 Answers0