React-router-dom :是否可以使用 Link 而不将用户路由到另一个页面?

Ahm*_*rib 5 html javascript reactjs react-router-dom

我有这张表:

<Table hover bordered striped responsive size="sm">
              <thead>
                <tr>
                  <th>Nom du fichier</th>
                  <th>Date et heure d'ajout</th>
                </tr>
              </thead>
              <tbody>
                {this.state.fichierJointsInformation.map(
                  (operationSavInformation, i) => {
                    return (
                      <tr key={i}>
                        <td>
                          <Link
                            to={""}
                            onClick={this.onFichierJointLinkClicked}
                          >
                            {operationSavInformation.nomFichierOriginal}
                          </Link>
                        </td>
                        <td>{operationSavInformation.createdAt}</td>
                      </tr>
                    );
                  }
                )}
              </tbody>
            </Table>
Run Code Online (Sandbox Code Playgroud)

它被渲染成这样:
在此输入图像描述

我想要实现的内容:当用户单击第一列的任何元素时,就会下载关联的文件。
所以onFichierJointLinkClickedonClick 监听器将处理 API 请求和其他一切。

<Link
                        to={""}
                        onClick={this.onFichierJointLinkClicked}
                      >
                        {operationSavInformation.nomFichierOriginal}
                      </Link>
Run Code Online (Sandbox Code Playgroud)

我的问题:LINKto中的道具是必需的。但是,我不想将用户路由到任何其他页面。我只想触发它。 onFichierJointLinkClicked

如果我删除该to道具,我显然会收到此错误:

index.js:1 Warning: Failed prop type: The prop `to` is marked as required in `Link`, but its value is `undefined`.
Run Code Online (Sandbox Code Playgroud)

Alo*_*ali 8

尝试放入#ie to="#",就像我正在做的那样。它对我来说工作得很好 -

请参见 -

<div className="pagination alternate pull-right">
  <ul>
    <li className={props.prevPage == null ? 'disabled' : ''}>
      <NavLink
        to="#"
        onClick={() => props.gotoPage(props.prevPage, props.noOfPages)}
      >
        Prev
      </NavLink>
    </li>
    {links}
    <li className={props.nextPage == null ? 'disabled' : ''}>
      <NavLink
        to="#"
        onClick={() => props.gotoPage(props.nextPage, props.noOfPages)}
      >
        Next
      </NavLink>
    </li>
  </ul>
</div>
Run Code Online (Sandbox Code Playgroud)