Skip to content
Advertisement

React Router Linking using

I am using React Router. I want when the user clicks on the button, it directs them to the page (endpoint) /form which has the UserForm component.

Here is my code wrapping the button:

          <Router>
          <Link to="/form" className="updateLink">
              <button className="updateBtn" onClick={() => {
                  this.update(id);
                  console.log(`Item Number: ${id} Was Updated Successfully`);
                        window.alert(`Item Number: ${id} Was Updated Successfully`);
                    }}>U</button>
          </Link>
          <Switch>
             <Router exact path="/form" component={UserForm} />
          </Switch>
          </Router>

Advertisement

Answer

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement