Skip to content

Commit d83d92c

Browse files
authored
fix: 🐛 link (#604)
use `Link` instead of `<a>` tag to prevent wrong link in this situation www.xxx.com/answer/
1 parent 57e93f2 commit d83d92c

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

ui/src/pages/Search/components/SearchItem/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
import { memo, FC } from 'react';
21+
import { Link } from 'react-router-dom';
2122
import { ListGroupItem } from 'react-bootstrap';
2223
import { useTranslation } from 'react-i18next';
2324

@@ -54,12 +55,12 @@ const Index: FC<Props> = ({ data }) => {
5455
style={{ marginTop: '2px' }}>
5556
{data.object_type === 'question' ? 'Q' : 'A'}
5657
</span>
57-
<a className="h5 mb-0 link-dark text-break" href={itemUrl}>
58+
<Link className="h5 mb-0 link-dark text-break" to={itemUrl}>
5859
{data.object.title}
5960
{data.object.status === 'closed'
6061
? ` [${t('closed', { keyPrefix: 'question' })}]`
6162
: null}
62-
</a>
63+
</Link>
6364
</div>
6465
<div className="d-flex flex-wrap align-items-center small text-secondary mb-2">
6566
<BaseUserCard data={data.object?.user_info} showAvatar={false} />

ui/src/pages/Users/Personal/components/Answers/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import { FC, memo } from 'react';
2121
import { ListGroup, ListGroupItem } from 'react-bootstrap';
2222
import { useTranslation } from 'react-i18next';
23+
import { Link } from 'react-router-dom';
2324

2425
import { FormatTime, Tag, Counts } from '@/components';
2526
import { pathFactory } from '@/router/pathFactory';
@@ -41,15 +42,15 @@ const Index: FC<Props> = ({ visible, data }) => {
4142
className="py-3 px-0 bg-transparent border-start-0 border-end-0"
4243
key={item.answer_id}>
4344
<h6 className="mb-2">
44-
<a
45-
href={pathFactory.answerLanding({
45+
<Link
46+
to={pathFactory.answerLanding({
4647
questionId: item.question_id,
4748
slugTitle: item.question_info?.url_title,
4849
answerId: item.answer_id,
4950
})}
5051
className="text-break">
5152
{item.question_info?.title}
52-
</a>
53+
</Link>
5354
</h6>
5455
<div className="d-flex align-items-center small text-secondary mb-2">
5556
<FormatTime

ui/src/pages/Users/Personal/components/Comments/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { FC, memo } from 'react';
2121
import { ListGroup, ListGroupItem } from 'react-bootstrap';
22+
import { Link } from 'react-router-dom';
2223

2324
import { pathFactory } from '@/router/pathFactory';
2425
import { FormatTime } from '@/components';
@@ -39,9 +40,9 @@ const Index: FC<Props> = ({ visible, data }) => {
3940
<ListGroupItem
4041
className="py-3 px-0 bg-transparent border-start-0 border-end-0"
4142
key={item.comment_id}>
42-
<a
43+
<Link
4344
className="text-break"
44-
href={
45+
to={
4546
item.object_type === 'question'
4647
? pathFactory.questionLanding(
4748
item.question_id,
@@ -54,7 +55,7 @@ const Index: FC<Props> = ({ visible, data }) => {
5455
})
5556
}>
5657
{item.title}
57-
</a>
58+
</Link>
5859
<div
5960
className="small mb-2 last-p text-break text-truncate-2"
6061
dangerouslySetInnerHTML={{

ui/src/pages/Users/Personal/components/DefaultList/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import { FC, memo } from 'react';
2121
import { ListGroup, ListGroupItem } from 'react-bootstrap';
2222
import { useTranslation } from 'react-i18next';
23+
import { Link } from 'react-router-dom';
2324

2425
import { FormatTime, Tag, BaseUserCard, Counts } from '@/components';
2526
import { pathFactory } from '@/router/pathFactory';
@@ -44,17 +45,17 @@ const Index: FC<Props> = ({ visible, tabName, data }) => {
4445
className="py-3 px-0 bg-transparent border-start-0 border-end-0"
4546
key={tabName === 'questions' ? item.question_id : item.id}>
4647
<h6 className="mb-2">
47-
<a
48+
<Link
4849
className="text-break"
49-
href={pathFactory.questionLanding(
50+
to={pathFactory.questionLanding(
5051
tabName === 'questions' ? item.question_id : item.id,
5152
item.url_title,
5253
)}>
5354
{item.title}
5455
{tabName === 'questions' && item.status === 'closed'
5556
? ` [${t('closed', { keyPrefix: 'question' })}]`
5657
: null}
57-
</a>
58+
</Link>
5859
</h6>
5960
<div className="d-flex flex-wrap align-items-center small text-secondary mb-2">
6061
{tabName === 'bookmarks' && (

ui/src/pages/Users/Personal/components/Reputation/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { FC, memo } from 'react';
2121
import { ListGroup, ListGroupItem } from 'react-bootstrap';
22+
import { Link } from 'react-router-dom';
2223

2324
import { FormatTime } from '@/components';
2425
import { pathFactory } from '@/router/pathFactory';
@@ -48,9 +49,9 @@ const Index: FC<Props> = ({ visible, data }) => {
4849
{item.reputation}
4950
</div>
5051
<div>
51-
<a
52+
<Link
5253
className="text-break"
53-
href={
54+
to={
5455
item.object_type === 'question'
5556
? pathFactory.questionLanding(
5657
item.question_id,
@@ -63,7 +64,7 @@ const Index: FC<Props> = ({ visible, data }) => {
6364
})
6465
}>
6566
{item.title}
66-
</a>
67+
</Link>
6768
<div className="d-flex align-items-center small text-secondary">
6869
<span>{item.rank_type}</span>
6970
<span className="split-dot" />

ui/src/pages/Users/Personal/components/TopList/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { FC, memo } from 'react';
2121
import { useTranslation } from 'react-i18next';
22+
import { Link } from 'react-router-dom';
2223

2324
import { pathFactory } from '@/router/pathFactory';
2425
import { Icon } from '@/components';
@@ -36,9 +37,9 @@ const Index: FC<Props> = ({ data, type }) => {
3637
<li
3738
className="mb-2"
3839
key={type === 'answer' ? item.answer_id : item.question_id}>
39-
<a
40+
<Link
4041
className="me-3"
41-
href={
42+
to={
4243
type === 'answer'
4344
? pathFactory.answerLanding({
4445
questionId: item.question_id,
@@ -51,7 +52,7 @@ const Index: FC<Props> = ({ data, type }) => {
5152
)
5253
}>
5354
{type === 'answer' ? item.question_info.title : item.title}
54-
</a>
55+
</Link>
5556

5657
<div className="d-inline-block text-secondary me-3 small">
5758
<Icon name="hand-thumbs-up-fill me-1" />

ui/src/pages/Users/Personal/components/Votes/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import { FC, memo } from 'react';
2121
import { ListGroup, ListGroupItem } from 'react-bootstrap';
22+
import { Link } from 'react-router-dom';
2223

2324
import { pathFactory } from '@/router/pathFactory';
2425
import { FormatTime } from '@/components';
@@ -46,9 +47,9 @@ const Index: FC<Props> = ({ visible, data }) => {
4647
{item.vote_type}
4748
</div>
4849
<div>
49-
<a
50+
<Link
5051
className="text-break"
51-
href={
52+
to={
5253
item.object_type === 'question'
5354
? pathFactory.questionLanding(
5455
item.question_id,
@@ -61,7 +62,7 @@ const Index: FC<Props> = ({ visible, data }) => {
6162
})
6263
}>
6364
{item.title}
64-
</a>
65+
</Link>
6566
<div className="d-flex align-items-center small text-secondary">
6667
<span>{item.object_type}</span>
6768

0 commit comments

Comments
 (0)