Skip to main content
The next/router module provides the Pages Router API, including the useRouter hook and default Router singleton for programmatic navigation.

Import

useRouter Hook

Returns a router instance with navigation methods and current route state.

Router Object

Properties

string
Current pathname (without basePath or query).
string
Current route pattern (with dynamic segments).
Record<string, string | string[]>
Query parameters and dynamic route params.
string
Full URL path including query string.
string
Configured base path from next.config.js.
string | undefined
Current locale (i18n).
string[] | undefined
All configured locales.
string | undefined
Default locale.
boolean
Whether the router is ready (always true in vinext).
boolean
Whether in preview mode (always false in vinext).
boolean
Whether the page is in fallback mode (ISR).

Methods

(url, as?, options?) => Promise<boolean>
Navigate to a new URL (pushes history entry).
Parameters:
  • url: string | UrlObject — Destination
  • as?: string — URL mask (legacy)
  • options?: { shallow?: boolean; scroll?: boolean; locale?: string }
Returns: Promise<boolean>true on success
(url, as?, options?) => Promise<boolean>
Navigate to a new URL (replaces history entry).
Same parameters as push().
() => void
Navigate to the previous page.
() => void
Hard reload the current page.
(url: string) => Promise<void>
Prefetch a page for faster navigation.
(cb: BeforePopStateCallback) => void
Register a callback to run before browser back/forward navigation.
RouterEvents
Event emitter for route changes.
Events:
  • routeChangeStart(url: string) — Before navigation starts
  • routeChangeComplete(url: string) — After navigation completes
  • routeChangeError(err: Error, url: string) — On navigation error

Router Singleton

The default export provides a router singleton for use outside components:
Methods and events are identical to useRouter().

UrlObject

Construct URLs programmatically:

Shallow Routing

Update the URL without triggering a full page navigation:
Deprecated in App Router — Use window.history.pushState() instead.

Scroll Control

Route Events

Listen for navigation events:

Available Events

  • routeChangeStart(url) — Fires before navigation
  • routeChangeComplete(url) — Fires after navigation succeeds
  • routeChangeError(err, url) — Fires on navigation error

Hash Navigation

Navigate to hash links:
Scroll to the target element automatically.

External URLs

External URLs trigger full page navigation:

Dynamic Routes

Access dynamic route parameters via router.query:

Catch-All Routes

i18n Routing

Navigate with locale support:

basePath Support

If basePath is configured, it’s automatically handled:

Limitations

Server-side routing: useRouter can only be called in client components. Use getServerSideProps to read route params on the server.
Shallow routing: Only updates query and asPath. Full page navigation still occurs if the route pattern changes.

Migration to App Router

App Router equivalents:

Source

View source code → Implementation: /home/daytona/workspace/source/packages/vinext/src/shims/router.ts