rsnext/test/e2e/useselectedlayoutsegment-s-in-pages-router/useselectedlayoutsegment-s-in-pages-router.test.ts
Balázs Orbán 9ae437f4b1
fix(navigation): allow useSelectedLayoutSegment(s) in Pages Router (#62584)
### 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
2024-02-29 13:14:52 +00:00

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'
)
})
})