Fix navigation inside tabs with a tableview replacing all query param… (#1218)

* fix navigation inside tabs with a tableview replacing all query params in url

* fix copilot suggested issues relating to encoding urls
This commit is contained in:
juhanikat
2026-07-12 13:44:50 +03:00
committed by GitHub
parent 9b98a91ee4
commit 4dff86367b
2 changed files with 8 additions and 6 deletions
@@ -419,7 +419,11 @@ export const TableView = <T extends MRT_RowData>({
) )
} }
const buildTableStateUrl = () => `${location.pathname}?${TABLE_STATE_URL_PARAM}=${encodeURIComponent(tableStateId)}` const buildTableStateUrl = () => {
const params = new URLSearchParams(location.search)
params.set(TABLE_STATE_URL_PARAM, tableStateId)
return `${location.pathname}?${params.toString()}`
}
const loadStateFromUrl = <TState extends MRT_ColumnFiltersState | MRT_SortingState | MRT_PaginationState>( const loadStateFromUrl = <TState extends MRT_ColumnFiltersState | MRT_SortingState | MRT_PaginationState>(
state: TableStateInUrl, state: TableStateInUrl,
+3 -5
View File
@@ -18,15 +18,13 @@ export const useSyncTabSearch = (tab: number) => {
}, [location.key, location.state]) }, [location.key, location.state])
useEffect(() => { useEffect(() => {
const nextSearch = `?tab=${tab}` const params = new URLSearchParams(location.search)
if (location.search === nextSearch) { if (params.get('tab') === String(tab)) return
return
}
navigate( navigate(
{ {
pathname: location.pathname, pathname: location.pathname,
search: nextSearch, search: `?tab=${tab}`,
}, },
{ {
replace: true, replace: true,