{"id":48465516,"url":"https://github.com/sectsect/use-placeholder-path","last_synced_at":"2026-04-07T04:31:02.342Z","repository":{"id":252492330,"uuid":"840593527","full_name":"sectsect/use-placeholder-path","owner":"sectsect","description":"A custom React hook to retrieve placeholder path in Next.js App Router. An alternative to router.pathname.","archived":false,"fork":false,"pushed_at":"2026-01-04T06:32:27.000Z","size":690,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-30T12:40:05.705Z","etag":null,"topics":["app-router","nextjs","path","pathname","placeholder-path","react","userouter"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@sect/use-placeholder-path","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sectsect.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-10T05:26:03.000Z","updated_at":"2026-01-04T06:31:49.000Z","dependencies_parsed_at":"2024-08-10T07:55:44.531Z","dependency_job_id":"bf125c54-1e3c-471a-ae5f-ece7d5acc4b2","html_url":"https://github.com/sectsect/use-placeholder-path","commit_stats":null,"previous_names":["sectsect/use-placeholder-path"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/sectsect/use-placeholder-path","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectsect%2Fuse-placeholder-path","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectsect%2Fuse-placeholder-path/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectsect%2Fuse-placeholder-path/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectsect%2Fuse-placeholder-path/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sectsect","download_url":"https://codeload.github.com/sectsect/use-placeholder-path/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sectsect%2Fuse-placeholder-path/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31500397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["app-router","nextjs","path","pathname","placeholder-path","react","userouter"],"created_at":"2026-04-07T04:31:02.263Z","updated_at":"2026-04-07T04:31:02.333Z","avatar_url":"https://github.com/sectsect.png","language":"TypeScript","readme":"# @sect/use-placeholder-path\n\n[![Release](https://github.com/sectsect/use-placeholder-path/actions/workflows/release.yml/badge.svg)](https://github.com/sectsect/use-placeholder-path/actions/workflows/release.yml) [![codecov](https://codecov.io/gh/sectsect/use-placeholder-path/graph/badge.svg?token=WsgZ81CmzZ)](https://codecov.io/gh/sectsect/use-placeholder-path) [![CodeQL](https://github.com/sectsect/use-placeholder-path/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/sectsect/use-placeholder-path/actions/workflows/github-code-scanning/codeql)\n\nA custom React hook to retrieve placeholder paths in Next.js App Router.\n\n## Why Use This Hook?\n\nNext.js 13+ App Router doesn't provide a built-in method to return the path of placeholder values, unlike `router.pathname` in Pages Router. This hook fills that gap, allowing you to get the placeholder path in the App Router, similar to how you would in the Pages Router.\n\n### Easing the Transition from Pages Router\n\nFor developers migrating from Pages Router to App Router, this hook can significantly reduce the pain points associated with the transition. It provides a familiar way to access placeholder paths, making it easier to port existing code and maintain consistency in your application's routing logic. By offering functionality similar to `router.pathname`, `usePlaceholderPath` helps bridge the gap between the two routing systems, allowing for a smoother migration process and reducing the need for extensive refactoring of route-dependent code.\n\n## Installation\n\n```bash\nnpm install @sect/use-placeholder-path\n# or\nyarn add @sect/use-placeholder-path\n# or\npnpm add @sect/use-placeholder-path\n```\n\n## Usage\n\n```tsx\n'use client';\n\nimport usePlaceholderPath from '@sect/use-placeholder-path';\n\nconst MyComponent = () =\u003e {\n  const placeholderPath = usePlaceholderPath();\n  \n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eCurrent placeholder path: {placeholderPath}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default MyComponent;\n```\n\n## API\n\n```typescript\nusePlaceholderPath(options?: UsePlaceholderPathOptions): string\n\ninterface UsePlaceholderPathOptions {\n  optionalCatchAllSegments?: string;\n}\n```\n\n- `optionalCatchAllSegments`: (optional) The name of the optional catch-all segment. If provided, enables handling of top-level optional catch-all segments.\n\n## Examples\n\n1. Route: `/users/123/posts/456`\n    - Result: `/users/[userId]/posts/[postId]`\n2. Catch-all Segments Route: `/blog/2024/08/15`\n    - Result: `/blog/[...slug]`\n3. Optional Catch-all Segments Route: `/shop/a/b/c`\n    - Result: `/shop/[[...slug]]`\n    \n\u003e [!NOTE]\n\u003e For Top-Level Optional Catch-all Segments, special handling may be required. See the **\"Known Issues\"** section for more details.\n\n## Notes\n\n- `usePlaceholderPath` requires the use of a [Client Component](https://nextjs.org/docs/app/building-your-application/rendering/client-components).\n\n## Known Issues\n\n### Detecting Top-Level Optional Catch-all Segments\n\nTop-Level Optional Catch-all Segments are expected to return `/folderName/[[...segmentName]]`, but currently `/folderName` is returned.\n\n- Expected: `/shop/[[...slug]]`\n- Actual: `/shop`\n\nThis is due to the technical limitations in detecting Top-Level Optional Catch-all Segments in the Next.js App Router.\n\nTo address this limitation, we've introduced an optional configuration:\n\n```typescript\nconst placeholderPath = usePlaceholderPath({\n  optionalCatchAllSegments: 'slug'\n});\n```\n\n## Changelog \n\nSee [CHANGELOG](https://github.com/sectsect/use-placeholder-path/blob/main/CHANGELOG.md).\n\n\u003cp align=\"center\"\u003e✌️\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n\u003csub\u003e\u003csup\u003eA little project by \u003ca href=\"https://github.com/sectsect\"\u003e@sectsect\u003c/a\u003e\u003c/sup\u003e\u003c/sub\u003e\n\u003c/p\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectsect%2Fuse-placeholder-path","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsectsect%2Fuse-placeholder-path","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsectsect%2Fuse-placeholder-path/lists"}