反应添加事件以将用户转换到路线

React add event to transition user to a route

在 React 中,我有以下组件,我想出售的每项服务都会重复这些组件。当用户单击按钮时,我想构建一个自定义 url 供他们访问。我正在使用反应路由器 dom。这是我的按钮代码

<button
  className="w-full block text-white py-4 rounded-sm"
  style={{ background: "#48746e" }}
  onClick={this.navigateToRoute}
>
  Continue booking
</button>

现在我可以访问构建 url 所需的所有数据,但我不知道如何执行转换以将它们带到那条路线。感谢任何提示

我会在里面打电话this.navigateToRoute

<Redirect to="/somewhere/else" />

或者如果你需要通过状态:

<Redirect
  to={{
    pathname: "/login",
    search: "?utm=your+face",
    state: { referrer: currentLocation }
  }}
/>