反应添加事件以将用户转换为路由

时间:2019-04-22 22:47:06

标签: reactjs react-router-dom

在React中,我要销售的每种服务都会重复以下组件。当用户单击按钮时,我要为其创建自定义URL。我正在使用反应路由器dom。这是我的按钮代码

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

现在,我可以访问构建URL所需的所有数据,但是我不知道如何执行转换以将其带到该路由。谢谢你的提示

1 个答案:

答案 0 :(得分:0)

我会在this.navigateToRoute内部呼叫

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

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

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