9ae437f4b1
### What? Do not fail when `useSelectedLayoutSegment` or `useSelectedLayoutSegments` APIs are called in the Pages Router. ### Why? This makes migration easier and creates consistency with our other App Router-specific APIs that inherit the same behavior. ### How? Similar to #47490, we return `null` if there is no Layout context (indicating being in Pages Router) Types are also overridden in the navigation compact module declaration which kicks in during start to correct the types if we detect a `pages/` directory. Note to reviewer: #47490 didn't add a test, so I added one top-level, let me know if you have a better suggestion for placing. Closes NEXT-2506 Fixes #61464
14 lines
440 B
TypeScript
14 lines
440 B
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('useSelectedLayoutSegment(s) in Pages Router', () => {
|
|
const { next } = nextTestSetup({ files: __dirname })
|
|
|
|
it('Should render with `useSelectedLayoutSegment(s) hooks', async () => {
|
|
const browser = await next.browser('/')
|
|
|
|
await browser.waitForElementByCss('#hello-world')
|
|
expect(await browser.elementByCss('#hello-world').text()).toBe(
|
|
'Hello World'
|
|
)
|
|
})
|
|
})
|