Skip to content

Ellipsis组件在Link下面点击展开如何阻止跳转页面 #5383

Answered by xiaoyao96
Sxxiong asked this question in Q&A
Discussion options

You must be logged in to vote

如果想要内容可跳转,展开/收起按钮不能跳转。应该这样:

import React from "react";
import { Ellipsis } from "antd-mobile";
import { Link, useNavigate } from "react-router-dom";

const content =
  "蚂蚁的企业级产品是一个庞大且复杂的体系。这类产品不仅量级巨大且功能复杂,而且变动和并发频繁,常常需要设计与开发能够快速的做出响应。同时这类产品中有存在很多类似的页面以及组件,可以通过抽象得到一些稳定且高复用性的内容。";

export default () => {
  let navigate = useNavigate();
  return (
    <>
      <Link
        to="/"
        onClick={(e) => {
          e.preventDefault();
          navigate("/");
        }}
      >
        <Ellipsis
          direction="end"
          content={content}
          expandText="展开"
          collapseText="收起"
          stopPropagationForActionButtons={["click"]}
        />
      </Link>
    </>
  );
}

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
2 replies
@Sxxiong
Comment options

@yaogengzhu
Comment options

Comment options

You must be logged in to vote
2 replies
@awmleer
Comment options

@miracles1919
Comment options

Comment options

You must be logged in to vote
1 reply
@xiaoyao96
Comment options

Comment options

You must be logged in to vote
2 replies
@awmleer
Comment options

@yaogengzhu
Comment options

Answer selected by awmleer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants