mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 05:52:16 +08:00

* Routing: Import useLocation from compat package * Add ComparRouter * Add CompatRouter * Fix tests * Add CompatRouter to TestProvider * Use findBy * Remove AppChromeService * Remove historyOptions * Routing: Fix alerting/test utils issues from react compat router usage (#92127) * Use render from test-utils * Use compat router * Convert more tests --------- Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com>
19 lines
628 B
TypeScript
19 lines
628 B
TypeScript
import { useLocation } from 'react-router-dom-v5-compat';
|
|
|
|
import { locationService } from '@grafana/runtime';
|
|
|
|
export type UseUrlParamsResult = [URLSearchParams, (params: Record<string, unknown>, replace?: boolean) => void];
|
|
|
|
/** @internal experimental */
|
|
export function useUrlParams(): UseUrlParamsResult {
|
|
const location = useLocation();
|
|
const params = new URLSearchParams(location.search);
|
|
|
|
const updateUrlParams = (params: Record<string, unknown>, replace?: boolean) => {
|
|
// Should find a way to use history directly here
|
|
locationService.partial(params, replace);
|
|
};
|
|
|
|
return [params, updateUrlParams];
|
|
}
|