diff --git a/ui/src/components/Header/components/NavItems/index.tsx b/ui/src/components/Header/components/NavItems/index.tsx index badd1b795..0b5c56504 100644 --- a/ui/src/components/Header/components/NavItems/index.tsx +++ b/ui/src/components/Header/components/NavItems/index.tsx @@ -20,7 +20,7 @@ import { FC, memo } from 'react'; import { Nav, Dropdown } from 'react-bootstrap'; import { useTranslation } from 'react-i18next'; -import { NavLink, useNavigate } from 'react-router-dom'; +import { NavLink, useMatch, useNavigate } from 'react-router-dom'; import type * as Type from '@/common/interface'; import { Avatar, Icon } from '@/components'; @@ -48,13 +48,27 @@ const Index: FC = ({ redDot, userInfo, logOut }) => { }); } }; + /** + * Automatically append `tag` information when creating a question + */ + const tagMatch = useMatch('/tags/:slugName'); + let askUrl = '/questions/ask'; + if (tagMatch && tagMatch.params.slugName) { + askUrl = `${askUrl}?tags=${encodeURIComponent(tagMatch.params.slugName)}`; + } return ( <>