Manage normal browser URL navigation
Browser single-page applications
TanStack · Function
Creates the default browser history implementation for TanStack Router. Use its returned history object when you want to provide browser navigation history explicitly.
createBrowserHistory creates the browser-oriented history implementation used by TanStack Router. It relies on the browser History API, and the resulting history object can be passed to the Router constructor or router options.
createBrowserHistory()A browser-oriented history instance compatible with TanStack Router's RouterHistory type.
import { createBrowserHistory } from '@tanstack/react-router'
const history = createBrowserHistory()
const router = createRouter({
routeTree,
history,
})
// Later, when the history instance is no longer needed:
history.destroy()Creates browser-backed history and supplies it explicitly to a TanStack Router instance.
Browser single-page applications
Custom router construction
Testing router setup
It creates the default TanStack Router history implementation for browser routing. The implementation uses the browser's History API to manage navigation state.
Follow-up: What happens if no history is supplied? The router creates and uses a new createBrowserHistory instance automatically.
Call createBrowserHistory to obtain a history object, then pass that object through the router's history option. This lets the router use that specific browser history instance.
Follow-up: Which option receives it? RouterOptions.history, whose type is RouterHistory.
It is intended for browser routing and is the default history type. For hash-based URLs, use createHashHistory instead, which is a different history type.
Follow-up: When would browser history be inappropriate? When the application specifically needs URL fragments to represent navigation state, hash history is the relevant alternative.
createHashHistoryRouterRouterOptions.historyRouterHistory