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— Destinationas?: string— URL mask (legacy)options?: { shallow?: boolean; scroll?: boolean; locale?: string }
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 startsrouteChangeComplete(url: string)— After navigation completesrouteChangeError(err: Error, url: string)— On navigation error
Router Singleton
The default export provides a router singleton for use outside components:useRouter().
UrlObject
Construct URLs programmatically:Navigation Options
Shallow Routing
Update the URL without triggering a full page navigation: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:External URLs
External URLs trigger full page navigation:Dynamic Routes
Access dynamic route parameters viarouter.query:
Catch-All Routes
i18n Routing
Navigate with locale support:basePath Support
IfbasePath is configured, it’s automatically handled:
Limitations
Migration to App Router
App Router equivalents:Source
View source code → Implementation:/home/daytona/workspace/source/packages/vinext/src/shims/router.ts