use location.hash instead search

This commit is contained in:
SrGooglo 2024-09-15 03:32:39 +00:00
parent f6fe72842d
commit 8a0093aa30
2 changed files with 5 additions and 5 deletions

View File

@ -48,7 +48,7 @@ export const Panel = (props) => {
export class PagePanelWithNavMenu extends React.Component { export class PagePanelWithNavMenu extends React.Component {
state = { state = {
activeTab: new URLSearchParams(window.location.search).get("type") ?? this.props.defaultTab ?? this.props.tabs[0].key, activeTab: new URLSearchParams(window.location.hash.replace("#", "?")).get("type") ?? this.props.defaultTab ?? this.props.tabs[0].key,
renders: [], renders: [],
} }
@ -157,7 +157,7 @@ export class PagePanelWithNavMenu extends React.Component {
} }
replaceQueryTypeToCurrentTab = (key) => { replaceQueryTypeToCurrentTab = (key) => {
app.history.replace(`${window.location.pathname}?type=${key ?? this.state.activeTab}`) document.location.hash = `type=${key ?? this.state.activeTab}`
} }
tabChange = async (key) => { tabChange = async (key) => {

View File

@ -4,15 +4,15 @@ export default ({
defaultKey = "0", defaultKey = "0",
queryKey = "key", queryKey = "key",
}) => { }) => {
const [activeKey, setActiveKey] = React.useState(new URLSearchParams(window.location.search).get(queryKey) ?? defaultKey) const [activeKey, setActiveKey] = React.useState(new URLSearchParams(window.location.hash.replace("#", "?")).get(queryKey) ?? defaultKey)
const replaceQueryTypeToCurrentTab = (key) => { const replaceQueryTypeToCurrentTab = (key) => {
if (!key) { if (!key) {
// delete query // delete query
return app.history.replace(window.location.pathname) return document.location.hash = null
} }
return app.history.replace(`${window.location.pathname}?${queryKey}=${key}`) return document.location.hash = `${queryKey}=${key}`
} }
const changeActiveKey = (key) => { const changeActiveKey = (key) => {