Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
How do you go to another page on button click in react?

FYI I'm learning reactjs. I have a quick question. I am developing a restaurant website and I want to make my "View Full Menu" button on my homepage(Home.js) take me to my menu.js file. I was able to redirect to the menu page on my App.js file, which is essentially where I have my functional navbar components. Please let me know if I need to show more code for this question. Also, I know that I probably have to use "onClick" on the button, but after doing some research, I cannot figure out how to go to the menu.js page. Thank you in advance.

            <div>
                <Card className="text-center">
                    <Card.Header>Featured</Card.Header>
                    
                    <Card.Body>
                        <Card.Title>Menu</Card.Title>
                        <Card.Text>
                            orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At consectetur lorem donec massa sapien. Euismod lacinia at quis risus sed vulputate odio ut.
                        </Card.Text>
                        <Button variant="primary">View Full Menu</Button>
                    </Card.Body>
                    <Card.Footer className="text-muted"></Card.Footer>
                </Card>
            </div>

Here is my working "menu" button on my App.js file.

function App () {
  return (
    
    <BrowserRouter>
    <div className="App">
      <Navigation />
      <Routes>
        <Route path="/" element={<Home />} />
        <Route path="/about" element={<About />} />
        <Route path="/menu" element={<MenuApp />} />
        <Route path= "/fire" element={<Fire />}/>
      </Routes>
    </div>
  </BrowserRouter>
  
  
  );
}
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

As well as the answers above, you could use the React Router Link component like this:

<Link to="/menu">
    View Full Menu
</Link>

Or the useHistory() hook as in this example from the docs:

import { useHistory } from "react-router-dom";

function HomeButton() {
  let history = useHistory();

  function handleClick() {
    history.push("/home");
  }

  return (
    <button type="button" onClick={handleClick}>
      Go home
    </button>
  );
}
about 4 years ago · Juan Pablo Isaza Report

0

Using react-router v6 you can navigate imperatively using useNavigate hook:

 const navigate = useNavigate();
 const handleMenuClick = () => navigate("/menu", { replace: true });

         <div>
            <Card className="text-center">
                <Card.Header>Featured</Card.Header>   
                <Card.Body>
                    <Card.Title>Menu</Card.Title>
                    <Card.Text>
                        orem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. At consectetur lorem donec massa sapien. Euismod lacinia at quis risus sed vulputate odio ut.
                    </Card.Text>
                    <Button variant="primary" onClick={handleMenuClick}>View Full Menu</Button>
                </Card.Body>
                <Card.Footer className="text-muted"></Card.Footer>
            </Card>
        </div>
about 4 years ago · Juan Pablo Isaza Report

0

You can use the useNavigate hook to navigate programmatically from one route to another.

import { useNavigate } from "react-router-dom";

const Component = () => {
  const navigate = useNavigate();
  const handleGoToMenu = () => navigate("menu");

  return (
    <Button variant="primary" onClick={handleGoToMenu}>View Full Menu</Button>
  );
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!