99 * Copyright (c) Facebook, Inc. and its affiliates.
1010 */
1111
12+ 'use client' ;
13+
1214import { Suspense } from 'react' ;
1315import * as React from 'react' ;
14- import { useRouter } from 'next/router' ;
16+ import { useRouter } from 'next/compat/ router' ;
1517import { SidebarNav } from './SidebarNav' ;
1618import { Footer } from './Footer' ;
1719import { Toc } from './Toc' ;
@@ -28,6 +30,7 @@ import {HomeContent} from './HomeContent';
2830import { TopNav } from './TopNav' ;
2931import cn from 'classnames' ;
3032import Head from 'next/head' ;
33+ import { usePathname } from 'next/navigation' ;
3134
3235import ( /* webpackPrefetch: true */ '../MDX/CodeBlock/CodeBlock' ) ;
3336
@@ -43,6 +46,8 @@ interface PageProps {
4346 } ;
4447 section : 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown' ;
4548 languages ?: Languages | null ;
49+ /** Should this being used with the Next.js App Router? */
50+ appRouter ?: boolean ;
4651}
4752
4853export function Page ( {
@@ -52,9 +57,14 @@ export function Page({
5257 meta,
5358 section,
5459 languages = null ,
60+ appRouter = false ,
5561} : PageProps ) {
56- const { asPath} = useRouter ( ) ;
57- const cleanedPath = asPath . split ( / [ \? \# ] / ) [ 0 ] ;
62+ const pagesRouter = useRouter ( ) ;
63+ const pathname = usePathname ( ) ! ;
64+ const cleanedPath = pagesRouter
65+ ? pagesRouter . asPath . split ( / [ \? \# ] / ) [ 0 ]
66+ : pathname ;
67+
5868 const { route, nextRoute, prevRoute, breadcrumbs, order} = getRouteMeta (
5969 cleanedPath ,
6070 routeTree
@@ -125,13 +135,15 @@ export function Page({
125135
126136 return (
127137 < >
128- < Seo
129- title = { title }
130- titleForTitleTag = { meta . titleForTitleTag }
131- isHomePage = { isHomePage }
132- image = { `/images/og-` + section + '.png' }
133- searchOrder = { searchOrder }
134- />
138+ { ! appRouter && (
139+ < Seo
140+ title = { title }
141+ titleForTitleTag = { meta . titleForTitleTag }
142+ isHomePage = { isHomePage }
143+ image = { `/images/og-` + section + '.png' }
144+ searchOrder = { searchOrder }
145+ />
146+ ) }
135147 { ( isHomePage || isBlogIndex ) && (
136148 < Head >
137149 < link
@@ -169,7 +181,7 @@ export function Page({
169181 < main className = "min-w-0 isolate" >
170182 < article
171183 className = "font-normal break-words text-primary dark:text-primary-dark"
172- key = { asPath } >
184+ key = { cleanedPath } >
173185 { content }
174186 </ article >
175187 < div
@@ -193,7 +205,9 @@ export function Page({
193205 </ main >
194206 </ Suspense >
195207 < div className = "hidden -mt-16 lg:max-w-custom-xs 2xl:block" >
196- { showToc && toc . length > 0 && < Toc headings = { toc } key = { asPath } /> }
208+ { showToc && toc . length > 0 && (
209+ < Toc headings = { toc } key = { cleanedPath } />
210+ ) }
197211 </ div >
198212 </ div >
199213 </ >
0 commit comments