`usePathname()` still returns string even with Typed Routes enabled
Open
@bgub is already working on this.
Since Aug 28, 2025.
linear: next
TypeScript
- Dominant language
- JavaScript
- Stars
- 142k
- Forks
- 32.5k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 351
Description
Link to the code that reproduces this issue
https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template
To Reproduce
-
Enable typed routes in
next.config.js:// next.config.js module.exports = { experimental: { typedRoutes: true, }, } -
Use
usePathname()in a Client Component:'use client' import { usePathname } from 'next/navigation' import type { Route } from 'next' export default function Example() { const pathname = usePathname() const go = (p: Route) => {/* ... */} // Type error (pathname is string): // Argument of type 'string' is not assignable to parameter of type 'Route'. go(pathname) return null }
Current vs. Expected behavior
Expected Behavior
- With typed routes enabled,
usePathname()should returnRoute(or a branded equivalent), or - Provide a new hook (e.g.,
useTypedPathname()/useCurrentRoute()) or a helper/guard (e.g.,asRoute(pathname)) to safely narrow the type at compile time.
Actual Behavior
usePathname()returnsstring, forcing unsafe casts and losing the refactor safety that Typed Routes aims to provide.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000
Available memory (MB): 32768
Available CPU cores: 10
Binaries:
Node: 24.6.0
npm: 11.5.1
Yarn: 4.9.1
pnpm: 8.6.2
Relevant Packages:
next: 15.5.2
eslint-config-next: 15.5.2
react: 19.1.1
react-dom: 19.1.1
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
TypeScript
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
When typedRoutes: true is enabled, Link and router.push/replace become type-safe (Route). However, usePathname() still returns string. Shouldn’t it return Route (or provide a typed alternative) to keep parity with Typed Routes?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.