This is an automated email from the ASF dual-hosted git repository.

shuai pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer.git


The following commit(s) were added to refs/heads/dev by this push:
     new 36b1560b fix: Automatically jump when the href of a Link component 
within a matching project is not a front-end route
36b1560b is described below

commit 36b1560b4552c686ffa79b54d37c50f768a7ff59
Author: shuai <[email protected]>
AuthorDate: Fri Jul 5 14:56:05 2024 +0800

    fix: Automatically jump when the href of a Link component within a matching 
project is not a front-end route
---
 ui/src/index.tsx | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/ui/src/index.tsx b/ui/src/index.tsx
index 6074ca72..e2930c08 100644
--- a/ui/src/index.tsx
+++ b/ui/src/index.tsx
@@ -60,8 +60,29 @@ const handleImgLoad = (evt: Event | UIEvent) => {
   }
 };
 
+/**
+ *Automatically jump when the href of a Link component within a matching 
project is not a front-end route.
+ *
+ */
+const handleClickLink = (evt: Event) => {
+  const { target } = evt;
+
+  if (target === null || !(target instanceof Element)) {
+    return;
+  }
+  if (!/A/i.test(target.nodeName)) {
+    return;
+  }
+
+  if (target.getAttribute('href')?.includes('/answer/api/')) {
+    evt.preventDefault();
+    window.location.href = target.getAttribute('href') || '';
+  }
+};
+
 document.addEventListener('error', handleImgLoad, true);
 document.addEventListener('load', handleImgLoad, true);
+document.addEventListener('click', handleClickLink, true);
 
 root.render(
   <React.StrictMode>

Reply via email to