Search code examples
javascriptreactjsroutesreact-routerdashboard

How to run a landing page with one section using ReactJS?


I have a login form with which the user accesses the dashboard. I want when I click a button on the landing page (.html) that the application redirects to the login form!

How can I run it with localhost:5000 for example?


Solution

  • If I understood well, you have to use history object from the props.

    For example state-less component:

    const LandingPage = ({ history }) => {
      return <button onClick={() => history.push('/login')}>Login</button> };
    

    Obviously you have to have a valid route.

    For example in App.jsx:

    <Route path="/login" exact component={Login} />