Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript: history.push does not exist after upgrading React Router

ErrorProperty 'push' does not exist on type 'History'

Short answer

The History type TypeScript knows is the browser's window.history, which has pushState but no push method. React Router v5 gave you its own history object with push. In v6 and later, call useNavigate and use navigate('/path') instead, and stop reading history from props.

  • Applies to React Router 6.30, React Router 7, TypeScript 5.9
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find where history comes from on the failing line. If it is an import from react-router-dom, a prop, or the bare global name changes which cause applies.

    grep -rn "history\.push\|useHistory" src/
  2. 2Match what you see, then jump to its fix

    1. 1No import or prop named history, and TypeScript resolves it to the DOM typehistory is the browser's global object, not the router'sFix
    2. 2useHistory is not exported, or history is not passed to the route componentCode written for React Router v5 runs on v6 or laterFix

What does the error look like?

  • Property 'push' does not exist on type 'History'

Cause 1 of 2

history is the browser's global object, not the router's

1Check

The browser's History interface lists back, forward, go, pushState and replaceState; it has no push method.

grep -n "history" src/components/LoginForm.tsx

2Fix

Use the router's navigate function instead of the global.

import { useNavigate } from "react-router-dom";

function LoginForm() {
  const navigate = useNavigate();
  return <button onClick={() => navigate("/home")}>Go</button>;
}

3Verify

TypeScript compiles and the click changes the route.

npx tsc --noEmit

Confirmed by developer.mozilla.org

Did this fix it?

Cause 2 of 2

Code written for React Router v5 runs on v6 or later

1Check

In v6 most call sites that used useHistory and history.push change to useNavigate and navigate. Route components no longer get router state from injected props; the guide says to use hooks.

npm ls react-router-dom react-router

2Fix

Replace useHistory with useNavigate. For replace, pass an option; for state, pass state.

const navigate = useNavigate();
navigate("/home");
navigate("/home", { replace: true });
navigate("/home", { state: { from: "login" } });

3Verify

The code compiles and replace or state behave as expected.

npx tsc --noEmit

Confirmed by reactrouter.com

Did this fix it?

How do I stop it coming back?

  • Read the upgrade guide before raising the major version of the router.
  • Do not use a global named history in app code; import the hook you need.
  • Keep navigation in components or hooks, so tests can wrap them in a router.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.