Returns the current route as an array of path segments. Segments match the file path structure, not the resolved URL values.
Use useSegments when you need to know which route file is active, rather than the resolved URL:
For resolved URL values, use usePathname or useParams.
You can strictly type segments for better type safety:
| Hook | Returns | Use Case |
|---|---|---|
useSegments() | ['users', '[id]'] | Route matching, guards |
usePathname() | '/users/123' | Display, analytics |
Edit this page on GitHub.