Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

During click on the back button in the react hooks web app, it is not navigating to the Home page

While navigating back in the react hooks web app, it is not displaying the Home page.Do I need to include anything else, could someone please advise here ? I couldn’t see any errors in console.

CSB link added:

https://codesandbox.io/s/blue-sun-rhog82?file=/src/components/home.js

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import Select from "react-select";
import { useNavigate } from "react-router-dom";
const options = [
  { value: "test1@test.com", label: "test1@test.com" },
  { value: "test2@test.com", label: "test2@test.com" },
  { value: "test3@test.com", label: "test3@test.com" }
];

const Register = () => {
  const navigate = useNavigate();

  const moveBack = () => {
    navigate("home");
  };

  return (
    <div className="wrapper">
      <h1>Lets us Know</h1>
      <form>
        <input type="text" name="candiate" /> <br></br>
        <br></br>
        <input type="text" name="mobile" /> <br></br>
        <br></br>
        <Select isMulti options={options} />
        <br></br>
        <textarea></textarea>
        <hr></hr>
        <button>Submit</button>
        <button onClick={moveBack}>Back</button>
      </form>
    </div>
  );
};
export default Register;

App.js

import "./styles.css";
import { BrowserRouter, Route, Routes, Switch } from "react-router-dom";
import Home from "./components/home";
import Register from "./components/register";

export default function App() {
  return (
    <div className="App">
      <BrowserRouter>
        {/* <Navigation /> */}
        <Routes>
          <Route path="/" element={<Home />}></Route>
        </Routes>
        <Routes>
          <Route path="/Register" element={<Register />}></Route>
        </Routes>
      </BrowserRouter>
    </div>
  );
}

>Solution :

Your issue is:

const moveBack = () => {
    navigate("home");
  };

Change it to:

const moveBack = () => {
    navigate("/");
  };

You’ve specified your </Home> component’s rendering route as the root of the directory:

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

So nothing was going to render when you navigated to /Home.

Hope this helps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading