0

So I used to pass data between different pages in react using the state inside the link component but now the props.history seems to be undefined. here is my router:

<Router>
        <Routes>
          <Route path="/auth/admin" exact element={<Login />} />
          <Route path="/admin" exact element={<AdminPage />} />
          <Route path="/admin/faculties" exact element={<Faculty />} />
          <Route path="/admin/addNewFaculty" exact element={<AddNewFaculty />} />
          <Route path="/admin/facultyEdit" exact element={<EditFaculty />} />
        </Routes>
</Router>

this is the link that I am using:

<Link
   to={{
         pathname: "/admin/facultyEdit",
         state: { id: item._id }
      }}
      style={{ marginRight: "10px" }}>

and this is what I am getting when trying to log the history in the faculty element:

console.log(this.props.history);

output: "undefined" Thank you in advance.

Drew Reese
  • 165,259
  • 14
  • 153
  • 181
  • Can you show the page where you're trying to access the history prop? – Piyush May 30 '22 at 11:57
  • I deleted everything in the page only the console.log is left – Christmas 545 May 30 '22 at 12:08
  • In `react-router-dom@6` route state is a top-level prop, not a property on the `to` prop object. Also, route state has *always* been accessed via the `location` object, not the `history` object. Use the `useLocation` hook to access the `location` object in the receiving component. – Drew Reese Jun 01 '22 at 00:01

0 Answers0