Skip to content

Commit 7d702ea

Browse files
Merge pull request #2331 from dxc-technology/Mil4n0r/fix_routing_problem
Reformated routing code in doc
2 parents d53af68 + cdc6ad3 commit 7d702ea

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

apps/website/pages/_app.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactElement, ReactNode, useEffect, useMemo, useState } from "react";
1+
import { ReactElement, ReactNode, useMemo, useState } from "react";
22
import type { NextPage } from "next";
33
import type { AppProps } from "next/app";
44
import Head from "next/head";
@@ -10,7 +10,6 @@ import StatusBadge from "@/common/StatusBadge";
1010
import "../global-styles.css";
1111
import createCache, { EmotionCache } from "@emotion/cache";
1212
import { CacheProvider } from "@emotion/react";
13-
import { usePathname } from "next/navigation";
1413
import Link from "next/link";
1514
import { GroupItem, Item, Section } from "../../../packages/lib/src/base-menu/types";
1615
import { isGroupItem } from "../../../packages/lib/src/base-menu/utils";
@@ -29,10 +28,9 @@ const clientSideEmotionCache = createCache({ key: "css", prepend: true });
2928
export default function App({ Component, pageProps, emotionCache = clientSideEmotionCache }: AppPropsWithLayout) {
3029
const getLayout = Component.getLayout || ((page) => page);
3130
const componentWithLayout = getLayout(<Component {...pageProps} />);
32-
const router = useRouter();
33-
const pathname = usePathname();
3431
const [filter, setFilter] = useState("");
3532
const [isExpanded, setIsExpanded] = useState(true);
33+
const { asPath: currentPath } = useRouter();
3634

3735
const filterSections = (sections: Section[], query: string): Section[] => {
3836
const q = query.trim().toLowerCase();
@@ -66,7 +64,7 @@ export default function App({ Component, pageProps, emotionCache = clientSideEmo
6664
const mapLinksToGroupItems = (sections: LinksSectionDetails[]): Section[] => {
6765
const matchPaths = (linkPath: string) => {
6866
const desiredPaths = [linkPath, `${linkPath}/code`];
69-
const pathToBeMatched = pathname?.split("#")[0]?.slice(0, -1);
67+
const pathToBeMatched = currentPath?.split("#")[0]?.slice(0, -1);
7068
return pathToBeMatched ? desiredPaths.includes(pathToBeMatched) : false;
7169
};
7270

@@ -88,16 +86,6 @@ export default function App({ Component, pageProps, emotionCache = clientSideEmo
8886
}));
8987
};
9088

91-
useEffect(() => {
92-
const paths = [...new Set(LinksSections.flatMap((s) => s.links.map((l) => l.path)))];
93-
const prefetchPaths = async () => {
94-
for (const path of paths) {
95-
await router.prefetch(path);
96-
}
97-
};
98-
void prefetchPaths();
99-
}, []);
100-
10189
// TODO: ADD NEW CATEGORIZATION
10290

10391
const filteredSections = useMemo(() => {

0 commit comments

Comments
 (0)