Skip to content

Commit

Permalink
fix: fix redirect to /
Browse files Browse the repository at this point in the history
  • Loading branch information
rookie-luochao committed Apr 21, 2024
1 parent a6c54ac commit ce2d625
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/components/head/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Dropdown, Input, message } from "antd";
import { SearchProps } from "antd/es/input";
import { useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { PartialParsedUrlQuery, toQueryString, useRouterQuery } from "react-router-toolkit";
import { useLocation, useNavigate } from "react-router-dom";
import { PartialParsedUrlQuery, parseQueryString, toQueryString } from "react-router-toolkit";
import { useOpenapiWithServiceInfoStore } from "../../core/store";
import { dsc } from "../../core/style/defaultStyleConfig";
import { flexCenterOpts } from "../../core/style/utils";
Expand Down Expand Up @@ -58,10 +58,11 @@ interface IQuery extends PartialParsedUrlQuery {
}

export function Head() {
const { pathname, search } = useLocation();
const navigate = useNavigate();
const { t } = useTranslation();
const { updateOpenapiWithServiceInfo } = useOpenapiWithServiceInfoStore();
const [query, setQuery] = useRouterQuery<IQuery>();
const query = parseQueryString(search) as IQuery;
const { serviceURL, importModeType, logon } = query;
const [isModalOpen, setIsModalOpen] = useState(false);
const isFlagRef = useRef(true);
Expand All @@ -72,10 +73,15 @@ export function Head() {
if (importModeType === ImportModeType.url && serviceURL && !logon) {
refetchOpenapiInfo(serviceURL);
} else {
setQuery((preState) => ({
...preState,
logon: "",
}));
navigate(
`${pathname}${toQueryString({
...(query || {}),
logon: "",
})}`,
{
replace: true,
},
);
}

isFlagRef.current = false;
Expand Down

0 comments on commit ce2d625

Please sign in to comment.