next.js icon indicating copy to clipboard operation
next.js copied to clipboard

useSelectedLayoutSegment throws error on root/home

Open Eloi-Perez opened this issue 3 years ago • 0 comments

Verify canary release

  • [X] I verified that the issue exists in the latest Next.js canary release

Provide environment information

next info:

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 16.17.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 12.3.2-canary.43
      eslint-config-next: 13.0.0
      react: 18.2.0
      react-dom: 18.2.0

What browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next dev

Describe the Bug

Using the new app layouts, when at root layout (localhost:3000/) if using useSelectedLayoutSegment this error is thrown: Error: No selected layout segment below the current level###

Expected Behavior

As I understand, useSelectedLayoutSegment() should be equal to an empty string in this case.

Link to reproduction

https://stackblitz.com/edit/vercel-next-js-fdhawa?file=app/nav-link.js

To Reproduce

Use useSelectedLayoutSegment() on a component of the layout.

Eloi-Perez avatar Oct 26 '22 18:10 Eloi-Perez