Capítulo 31 de 57
TanStack Router relies on a history abstraction from @tanstack/history; a browser history instance is created automatically by default, but you can supply createBrowserHistory, createHashHistory, or createMemoryHistory explicitly to createRouter({ history }) for different environments.
createBrowserHistory: The default; uses the browser's native History API (pushState/popState) to manage navigation.createHashHistory: Tracks routes via the URL hash (#/path) instead of the path itself; useful when the server can't be configured to rewrite all requests to index.html, or in environments without a configurable server.createMemoryHistory({ initialEntries }): Keeps history entirely in memory rather than touching the URL/browser; useful for non-browser environments, testing, or when components shouldn't interact with the real URL. initialEntries seeds the starting stack (e.g. ['/']).createRouter({ routeTree, history: customHistory }).import { createMemoryHistory, createRouter } from '@tanstack/react-router'
const memoryHistory = createMemoryHistory({
initialEntries: ['/'], // Pass your initial url
})
const router = createRouter({ routeTree, history: memoryHistory })
index.html aren't possible, and memory history for tests, SSR bootstrapping, or embedded/non-browser environments.history instance is a pluggable dependency injected at createRouter() time, not hardcoded, so the same route tree can run under different history backends without route code changes.NavigateOptions.replace interacts with whichever history instance is active.