Skip to content

Commit 7b408b1

Browse files
frano-mclaude
andcommitted
feat: useRouter().pathname → usePathname() (#928)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 745c127 commit 7b408b1

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/hooks/stateSyncManager/hooks/UseStateSync/hook.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { usePathname } from "next/navigation";
12
import { NextRouter, useRouter } from "next/router";
23
import { useEffect } from "react";
34
import { ROUTER_METHOD } from "../../../../providers/exploreState/actions/stateToUrl/types";
@@ -10,7 +11,8 @@ export const useStateSync = <Action>({
1011
dispatch,
1112
state,
1213
}: UseStateSyncManagerProps<Action>): void => {
13-
const { basePath, isReady, pathname, query } = useRouter();
14+
const { basePath, isReady, query } = useRouter();
15+
const pathname = usePathname() ?? "";
1416
const { onClearPopRef, popRef } = useWasPop();
1517

1618
// Extract the query from the state.

src/hooks/useUpdateURLCatalogParam.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ import { useExploreState } from "./useExploreState";
77
*/
88
export const useUpdateURLCatalogParams = (): void => {
99
const { exploreState } = useExploreState();
10+
// `pathname` is intentionally still read from useRouter() here so it stays as
11+
// the route pattern (e.g. `/[entityListType]/[entityId]`). The pattern is
12+
// required by the Router.replace({ pathname, query }) call below — Next.js
13+
// interpolates dynamic-param keys (entityListType, entityId, …) out of the
14+
// query into the path. usePathname() would return the already-resolved URL,
15+
// which on dynamic routes would leave those keys in the query string. The
16+
// migration to usePathname()/router.replace() is tracked in #930 and #931
17+
// and will be done together with the Router.replace refactor.
1018
const { basePath, pathname, query } = useRouter();
1119
const { catalogState } = exploreState;
1220

src/views/ExportMethodView/exportMethodView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useRouter } from "next/router";
1+
import { usePathname } from "next/navigation";
22
import { JSX } from "react";
33
import { ComponentCreator } from "../../components/ComponentCreator/ComponentCreator";
44
import { BackPageView } from "../../components/Layout/components/BackPage/backPageView";
@@ -8,7 +8,7 @@ import { useUpdateURLSearchParams } from "../../hooks/useUpdateURLSearchParams";
88

99
export const ExportMethodView = (): JSX.Element => {
1010
useUpdateURLSearchParams();
11-
const { pathname } = useRouter();
11+
const pathname = usePathname() ?? "";
1212
const { exportMethods, tabs } = useExportConfig();
1313
const { sideColumn } = tabs[0];
1414
const { mainColumn, top } =

0 commit comments

Comments
 (0)