Skip to content

usePathname() still returns string even with Typed Routes enabled #83092

@yaquawa

Description

@yaquawa

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template

To Reproduce

  1. Enable typed routes in next.config.js:

    // next.config.js
    module.exports = {
      experimental: {
        typedRoutes: true,
      },
    }
  2. 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
    }
Image

Current vs. Expected behavior

Expected Behavior

  • With typed routes enabled, usePathname() should return Route (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() returns string, 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?

NEXT-4703

Metadata

Metadata

Assignees

Labels

TypeScriptRelated to types with Next.js.linear: nextConfirmed issue that is tracked by the Next.js team.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions