vercel / next.js

The React Framework
https://nextjs.org
MIT License
124.94k stars 26.68k forks source link

`useSelectedLayoutSegment` returns names of route groups #51677

Open typeofweb opened 1 year ago

typeofweb commented 1 year ago

Verify canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 16.17.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 7.1.0
    Relevant packages:
      next: 13.4.8-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true)

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/wandering-hill-3f5rtr?file=%2Fapp%2F%28group%29%2Fsome-route%2Fpage.tsx

To Reproduce

(or just visit the above codesandbox and navigate to /some-route: https://3f5rtr-3000.csb.app/some-route

Describe the Bug

useSelectedLayoutSegment() returns "(group)" useSelectedLayoutSegments() returns ["(group)", "some-route"]

Expected Behavior

useSelectedLayoutSegment() returns "some-route" useSelectedLayoutSegments() returns ["some-route"]

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

ScreamZ commented 4 months ago

@leerob @ijjk @timneutkens Guys I guess this is a real issue and bug that need a fix. Almost one year ago that this has been opened :x

CTOverton commented 3 weeks ago

@typeofweb since it's been a year and this is unresolved, have you made a workaround?

ScreamZ commented 3 weeks ago

You can do workaround with a bit of algorithmic, either using usePathname or using those hooks but filtering output removing things with ()