Repository: TanStack/router (ts)

Issue:
Unexpected behavior of memory history back()
### Describe the bug

I am using the memory history for routing.
While testing the back functionality, I noticed that the behavior is unexpected.
For example, routing between pages
- A -> B -> C
- back
- -> D
- back

results in __C__ instead of __B__.



### Your Example Website or App

https://stackblitz.com/edit/tanstack-router-pcmnka?file=src%2Froutes%2Findex.tsx

### Steps to Reproduce the Bug or Issue

1. Click on "Go to page A"
2. Click on "Go to page B"
3. Click on "Go to page C"
4. Click "Back"
5. Click on "Go to page D"
6. Click on "Back"

### Expected behavior

As a user, I would expect the last back navigation to result in Page B. 

### Screenshots or Videos


https://github.com/TanStack/router/assets/25435740/6a14735a-923e-4bc3-beae-4e7930ba296d



### Platform

- OS: macOS
- Browser: Chrome
- Version: Version 126.0.6478.127 (Official Build) (arm64)
- Tanstack Router Version: 1.43.12


### Additional context

We changed the `pushState` function in the `createMemoryHistory` function to remove all entries after the `index` before pushing the new state.

| Action                                    | Entries                | Index   | Page |
|-------------------------------------------|------------------------|---------|------|
| Go to C        | A -> B -> C            | 2       | C    |
| Go back              | A -> B -> C            | 1       | B    |
| Go to D          | A -> B -> C -> D       | 3       | D    |
| Go back         | A -> B -> C -> D       | 2       | C    |

### Our change:
```
  // This function differs from the original tanstack/react-router implementation
  pushState: (path, state) => {
    currentState = state;
    // Removes all subsequent entries after the current index to start a new branch
    if (index < entries.length - 1) {
      entries.splice(index + 1);
    }
    entries.push(path);
    index = Math.max(entries.length - 1, 0);
  },
```

Pull request:
fix(history): fix bugs in push and back of createMemoryHistory
fixes #1916

Patch:
diff --git a/examples/react/authenticated-routes/package.json b/examples/react/authenticated-routes/package.json
index a29cb97e0..a3486f516 100644
--- a/examples/react/authenticated-routes/package.json
+++ b/examples/react/authenticated-routes/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-default-search-params/package.json b/examples/react/basic-default-search-params/package.json
index b8783c3d6..025c12f38 100644
--- a/examples/react/basic-default-search-params/package.json
+++ b/examples/react/basic-default-search-params/package.json
@@ -10,8 +10,8 @@
   },
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-file-based-codesplitting/package.json b/examples/react/basic-file-based-codesplitting/package.json
index 3cc2b915e..ee4084319 100644
--- a/examples/react/basic-file-based-codesplitting/package.json
+++ b/examples/react/basic-file-based-codesplitting/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-file-based/package.json b/examples/react/basic-file-based/package.json
index 3bf7e3859..fc99b8ad5 100644
--- a/examples/react/basic-file-based/package.json
+++ b/examples/react/basic-file-based/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-react-query-file-based/package.json b/examples/react/basic-react-query-file-based/package.json
index 953770c7c..9fc4f7593 100644
--- a/examples/react/basic-react-query-file-based/package.json
+++ b/examples/react/basic-react-query-file-based/package.json
@@ -11,9 +11,9 @@
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
     "@tanstack/react-query-devtools": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-react-query/package.json b/examples/react/basic-react-query/package.json
index f4e492a40..bb950b112 100644
--- a/examples/react/basic-react-query/package.json
+++ b/examples/react/basic-react-query/package.json
@@ -11,8 +11,8 @@
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
     "@tanstack/react-query-devtools": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
diff --git a/examples/react/basic-ssr-file-based/package.json b/examples/react/basic-ssr-file-based/package.json
index 1614b7229..4be2eb341 100644
--- a/examples/react/basic-ssr-file-based/package.json
+++ b/examples/react/basic-ssr-file-based/package.json
@@ -11,10 +11,10 @@
     "debug": "node --inspect-brk server"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "get-port": "^7.0.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic-ssr-streaming-file-based/package.json b/examples/react/basic-ssr-streaming-file-based/package.json
index dd1e0740d..aed22c695 100644
--- a/examples/react/basic-ssr-streaming-file-based/package.json
+++ b/examples/react/basic-ssr-streaming-file-based/package.json
@@ -11,10 +11,10 @@
     "debug": "node --inspect-brk server"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "get-port": "^7.0.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/basic/package.json b/examples/react/basic/package.json
index 5c6ddd74c..6932965f2 100644
--- a/examples/react/basic/package.json
+++ b/examples/react/basic/package.json
@@ -10,8 +10,8 @@
   },
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
diff --git a/examples/react/deferred-data/package.json b/examples/react/deferred-data/package.json
index 2822f9c17..e5f56a06b 100644
--- a/examples/react/deferred-data/package.json
+++ b/examples/react/deferred-data/package.json
@@ -9,8 +9,8 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/kitchen-sink-file-based/package.json b/examples/react/kitchen-sink-file-based/package.json
index 424fc706c..d45bc06b0 100644
--- a/examples/react/kitchen-sink-file-based/package.json
+++ b/examples/react/kitchen-sink-file-based/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/kitchen-sink-react-query-file-based/package.json b/examples/react/kitchen-sink-react-query-file-based/package.json
index 3fd34ffde..d582f7733 100644
--- a/examples/react/kitchen-sink-react-query-file-based/package.json
+++ b/examples/react/kitchen-sink-react-query-file-based/package.json
@@ -11,9 +11,9 @@
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
     "@tanstack/react-query-devtools": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/kitchen-sink-react-query/package.json b/examples/react/kitchen-sink-react-query/package.json
index 8f0a5a2ce..8704929d5 100644
--- a/examples/react/kitchen-sink-react-query/package.json
+++ b/examples/react/kitchen-sink-react-query/package.json
@@ -11,8 +11,8 @@
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
     "@tanstack/react-query-devtools": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/kitchen-sink/package.json b/examples/react/kitchen-sink/package.json
index dd6bffae3..00fbd1387 100644
--- a/examples/react/kitchen-sink/package.json
+++ b/examples/react/kitchen-sink/package.json
@@ -9,8 +9,8 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "immer": "^10.0.3",
     "react": "^18.2.0",
diff --git a/examples/react/large-file-based/package.json b/examples/react/large-file-based/package.json
index 4979301fa..e6e919dd1 100644
--- a/examples/react/large-file-based/package.json
+++ b/examples/react/large-file-based/package.json
@@ -12,9 +12,9 @@
   },
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/location-masking/package.json b/examples/react/location-masking/package.json
index 92eb0d332..d1bed16eb 100644
--- a/examples/react/location-masking/package.json
+++ b/examples/react/location-masking/package.json
@@ -11,8 +11,8 @@
   "dependencies": {
     "@radix-ui/react-dialog": "^1.0.5",
     "@tanstack/react-query": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
diff --git a/examples/react/navigation-blocking/package.json b/examples/react/navigation-blocking/package.json
index ef68b4240..391024dad 100644
--- a/examples/react/navigation-blocking/package.json
+++ b/examples/react/navigation-blocking/package.json
@@ -10,8 +10,8 @@
   },
   "dependencies": {
     "@tanstack/react-query": "^5.17.8",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
diff --git a/examples/react/quickstart-file-based/package.json b/examples/react/quickstart-file-based/package.json
index 10a8420ed..f421aaaf8 100644
--- a/examples/react/quickstart-file-based/package.json
+++ b/examples/react/quickstart-file-based/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
     "immer": "^10.0.3",
     "react": "^18.2.0",
     "react-dom": "^18.2.0",
diff --git a/examples/react/quickstart-rspack-file-based/package.json b/examples/react/quickstart-rspack-file-based/package.json
index 0d1cfc96c..458f68a6b 100644
--- a/examples/react/quickstart-rspack-file-based/package.json
+++ b/examples/react/quickstart-rspack-file-based/package.json
@@ -8,15 +8,15 @@
     "preview": "rsbuild preview"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "react": "^18.3.1",
     "react-dom": "^18.3.1"
   },
   "devDependencies": {
     "@rsbuild/core": "^0.7.9",
     "@rsbuild/plugin-react": "^0.7.9",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/router-plugin": "^1.43.13",
     "@types/react": "^18.3.3",
     "@types/react-dom": "^18.3.0",
     "typescript": "^5.5.3"
diff --git a/examples/react/quickstart-webpack-file-based/package.json b/examples/react/quickstart-webpack-file-based/package.json
index 78ab87f81..71a365226 100644
--- a/examples/react/quickstart-webpack-file-based/package.json
+++ b/examples/react/quickstart-webpack-file-based/package.json
@@ -7,14 +7,14 @@
     "build": "webpack build"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "react": "^18.3.1",
     "react-dom": "^18.3.1"
   },
   "devDependencies": {
     "@swc/core": "^1.3.102",
-    "@tanstack/router-plugin": "^1.43.12",
+    "@tanstack/router-plugin": "^1.43.13",
     "@types/react": "^18.3.3",
     "@types/react-dom": "^18.3.0",
     "html-webpack-plugin": "^5.6.0",
diff --git a/examples/react/quickstart/package.json b/examples/react/quickstart/package.json
index db6ac06ff..91bdbc9a7 100644
--- a/examples/react/quickstart/package.json
+++ b/examples/react/quickstart/package.json
@@ -9,8 +9,8 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
   },
diff --git a/examples/react/scroll-restoration/package.json b/examples/react/scroll-restoration/package.json
index bda5ca289..c33f72523 100644
--- a/examples/react/scroll-restoration/package.json
+++ b/examples/react/scroll-restoration/package.json
@@ -9,9 +9,9 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
     "@tanstack/react-virtual": "^3.0.1",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/router-devtools": "^1.43.13",
     "react": "^18.2.0",
     "react-dom": "^18.2.0"
   },
diff --git a/examples/react/start-basic-counter/package.json b/examples/react/start-basic-counter/package.json
index 546c19394..aab5e50b1 100644
--- a/examples/react/start-basic-counter/package.json
+++ b/examples/react/start-basic-counter/package.json
@@ -12,8 +12,8 @@
     "format": "prettier --write '**/*' --ignore-unknown"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.2",
-    "@tanstack/start": "^1.43.2",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "@typescript-eslint/parser": "^7.2.0",
     "react": "^18.3.1",
     "react-dom": "^18.3.1",
diff --git a/examples/react/start-basic-react-query/package.json b/examples/react/start-basic-react-query/package.json
index 7229ddc26..32aaf6455 100644
--- a/examples/react/start-basic-react-query/package.json
+++ b/examples/react/start-basic-react-query/package.json
@@ -16,11 +16,11 @@
   "dependencies": {
     "@tanstack/react-query": "^5.49.2",
     "@tanstack/react-query-devtools": "^5.48.0",
-    "@tanstack/react-router": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
     "@tanstack/react-router-with-query": "^1.43.2",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "@typescript-eslint/parser": "^7.2.0",
     "@vitejs/plugin-react": "^4",
     "dotenv": "^16.4.5",
diff --git a/examples/react/start-basic-rsc/package.json b/examples/react/start-basic-rsc/package.json
index 470803d82..2a99b128a 100644
--- a/examples/react/start-basic-rsc/package.json
+++ b/examples/react/start-basic-rsc/package.json
@@ -13,10 +13,10 @@
   },
   "dependencies": {
     "@babel/plugin-syntax-typescript": "^7.24.1",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "redaxios": "^0.5.0",
     "tailwind-merge": "^1.14.0",
     "vinxi": "^0.3.11"
diff --git a/examples/react/start-basic/package.json b/examples/react/start-basic/package.json
index 8c3aa1a1f..3738472cc 100644
--- a/examples/react/start-basic/package.json
+++ b/examples/react/start-basic/package.json
@@ -14,10 +14,10 @@
     "test:e2e:replay": "playwright test --project=replay-chromium"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "@typescript-eslint/parser": "^7.2.0",
     "@vitejs/plugin-react": "^4",
     "dotenv": "^16.4.5",
diff --git a/examples/react/start-trellaux/package.json b/examples/react/start-trellaux/package.json
index 5f3d58dbb..cfcc6ac1d 100644
--- a/examples/react/start-trellaux/package.json
+++ b/examples/react/start-trellaux/package.json
@@ -14,11 +14,11 @@
   "dependencies": {
     "@tanstack/react-query": "^5.49.2",
     "@tanstack/react-query-devtools": "^5.49.2",
-    "@tanstack/react-router": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
     "@tanstack/react-router-with-query": "^1.43.2",
-    "@tanstack/router-devtools": "^1.43.12",
-    "@tanstack/router-plugin": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/router-devtools": "^1.43.13",
+    "@tanstack/router-plugin": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "@typescript-eslint/parser": "^7.2.0",
     "@vitejs/plugin-react": "^4",
     "isbot": "^3.7.0",
diff --git a/examples/react/wip-trpc-react-query/package.json b/examples/react/wip-trpc-react-query/package.json
index 3d25e6097..996ef386c 100644
--- a/examples/react/wip-trpc-react-query/package.json
+++ b/examples/react/wip-trpc-react-query/package.json
@@ -13,8 +13,8 @@
   "dependencies": {
     "@tanstack/react-query": "^4.36.1",
     "@tanstack/react-query-devtools": "^4.36.1",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "@trpc/client": "^10.45.0",
     "@trpc/react-query": "^10.45.0",
     "@trpc/server": "^10.45.0",
diff --git a/examples/react/wip-waku-rsc/package.json b/examples/react/wip-waku-rsc/package.json
index 179d1eaaf..37b0e8387 100644
--- a/examples/react/wip-waku-rsc/package.json
+++ b/examples/react/wip-waku-rsc/package.json
@@ -9,8 +9,8 @@
   },
   "dependencies": {
     "@hono/node-server": "^1.4.1",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "hono": "^3.12.0",
     "react": "18.3.0-canary-0cdfef19b-20231211",
     "react-dom": "18.3.0-canary-0cdfef19b-20231211",
diff --git a/examples/react/wip-with-bling/package.json b/examples/react/wip-with-bling/package.json
index 048c5fcb9..b41012041 100644
--- a/examples/react/wip-with-bling/package.json
+++ b/examples/react/wip-with-bling/package.json
@@ -12,10 +12,10 @@
   },
   "dependencies": {
     "@tanstack/bling": "^0.5.0",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/start": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/start": "^1.43.13",
     "@tanstack/react-store": "^0.2.1",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "fastify": "^4.25.2",
     "get-port": "^7.0.0",
diff --git a/examples/react/wip-with-framer-motion/package.json b/examples/react/wip-with-framer-motion/package.json
index d82a4657d..7a1e50ca2 100644
--- a/examples/react/wip-with-framer-motion/package.json
+++ b/examples/react/wip-with-framer-motion/package.json
@@ -9,8 +9,8 @@
     "start": "vite"
   },
   "dependencies": {
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "redaxios": "^0.5.0",
     "framer-motion": "^10.17.9",
     "immer": "^10.0.3",
diff --git a/examples/react/with-trpc/package.json b/examples/react/with-trpc/package.json
index 3ca0e6075..25f70aaa9 100644
--- a/examples/react/with-trpc/package.json
+++ b/examples/react/with-trpc/package.json
@@ -13,8 +13,8 @@
   "dependencies": {
     "@tanstack/react-query": "^4.36.1",
     "@tanstack/react-query-devtools": "^4.36.1",
-    "@tanstack/react-router": "^1.43.12",
-    "@tanstack/router-devtools": "^1.43.12",
+    "@tanstack/react-router": "^1.43.13",
+    "@tanstack/router-devtools": "^1.43.13",
     "@trpc/client": "^10.45.0",
     "@trpc/react-query": "^10.45.0",
     "@trpc/server": "^10.45.0",
diff --git a/packages/history/package.json b/packages/history/package.json
index ea7c2580d..762538c13 100644
--- a/packages/history/package.json
+++ b/packages/history/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/history",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
@@ -29,6 +29,8 @@
     "test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js",
     "test:types:ts55": "tsc",
     "test:build": "publint --strict",
+    "test:unit": "vitest",
+    "test:unit:dev": "pnpm run test:unit --watch",
     "build": "vite build"
   },
   "type": "module",
diff --git a/packages/history/src/index.ts b/packages/history/src/index.ts
index 15d477117..b91c680a0 100644
--- a/packages/history/src/index.ts
+++ b/packages/history/src/index.ts
@@ -359,6 +359,11 @@ export function createMemoryHistory(
 
     pushState: (path, state) => {
       currentState = state
+      entries.splice
+      // Removes all subsequent entries after the current index to start a new branch
+      if (index < entries.length - 1) {
+        entries.splice(index + 1)
+      }
       entries.push(path)
       index = Math.max(entries.length - 1, 0)
     },
@@ -368,7 +373,7 @@ export function createMemoryHistory(
     },
     back: () => {
       currentState = assignKey(currentState)
-      index--
+      index = Math.max(index - 1, 0)
     },
     forward: () => {
       currentState = assignKey(currentState)
diff --git a/packages/react-cross-context/package.json b/packages/react-cross-context/package.json
index dfeedec6d..0cca94f49 100644
--- a/packages/react-cross-context/package.json
+++ b/packages/react-cross-context/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/react-cross-context",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/react-router/package.json b/packages/react-router/package.json
index e83c280d5..6c6e78721 100644
--- a/packages/react-router/package.json
+++ b/packages/react-router/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/react-router",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-cli/package.json b/packages/router-cli/package.json
index 1cbf8219e..9c617f245 100644
--- a/packages/router-cli/package.json
+++ b/packages/router-cli/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-cli",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-devtools/package.json b/packages/router-devtools/package.json
index 713ed42e6..d3743e9be 100644
--- a/packages/router-devtools/package.json
+++ b/packages/router-devtools/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-devtools",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-generator/package.json b/packages/router-generator/package.json
index 2e8a1a14d..651138a70 100644
--- a/packages/router-generator/package.json
+++ b/packages/router-generator/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-generator",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-plugin/package.json b/packages/router-plugin/package.json
index 74507295c..40b0c1520 100644
--- a/packages/router-plugin/package.json
+++ b/packages/router-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-plugin",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/router-vite-plugin/package.json b/packages/router-vite-plugin/package.json
index 899e58ac2..56b84470f 100644
--- a/packages/router-vite-plugin/package.json
+++ b/packages/router-vite-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/router-vite-plugin",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start-vite-plugin/package.json b/packages/start-vite-plugin/package.json
index 7616e9113..7b08b3c2d 100644
--- a/packages/start-vite-plugin/package.json
+++ b/packages/start-vite-plugin/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/start-vite-plugin",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start/package.json b/packages/start/package.json
index 8720faed0..d077f26bc 100644
--- a/packages/start/package.json
+++ b/packages/start/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@tanstack/start",
-  "version": "1.43.12",
+  "version": "1.43.13",
   "description": "Modern and scalable routing for React applications",
   "author": "Tanner Linsley",
   "license": "MIT",
diff --git a/packages/start/src/client/index.tsx b/packages/start/src/client/index.tsx
index 2aea86da1..eaf4d7bc8 100644
--- a/packages/start/src/client/index.tsx
+++ b/packages/start/src/client/index.tsx
@@ -6,6 +6,7 @@ export {
   type FetcherOptionsBase,
   type FetcherOptions,
   type FetchFn,
+  type FetchFnCtx,
   type CompiledFetcherFnOptions,
   type CompiledFetcherFn,
   type Fetcher,


Test patch:
diff --git a/packages/history/tests/createMemoryHistory.test.ts b/packages/history/tests/createMemoryHistory.test.ts
new file mode 100644
index 000000000..d4d2326f7
--- /dev/null
+++ b/packages/history/tests/createMemoryHistory.test.ts
@@ -0,0 +1,54 @@
+import { describe, expect, test } from 'vitest'
+import { createMemoryHistory } from '../src'
+
+describe('createMemoryHistory', () => {
+  test('back', () => {
+    const initialEntry = '/initial'
+    const history = createMemoryHistory({ initialEntries: [initialEntry] })
+    history.push('/a')
+    history.push('/b')
+    history.push('/c')
+    history.back()
+    expect(history.location.pathname).toBe('/b')
+    history.back()
+    expect(history.location.pathname).toBe('/a')
+    history.back()
+    expect(history.location.pathname).toBe(initialEntry)
+    // check that back does nothing when there is no back history
+    history.back()
+    expect(history.location.pathname).toBe(initialEntry)
+  })
+
+  test('forward', () => {
+    const history = createMemoryHistory()
+    history.push('/a')
+    history.push('/b')
+    history.push('/c')
+    history.back()
+    history.back()
+    expect(history.location.pathname).toBe('/a')
+    history.forward()
+    expect(history.location.pathname).toBe('/b')
+    history.forward()
+    expect(history.location.pathname).toBe('/c')
+    // check that forward does nothing when there is no forward history
+    history.forward()
+    expect(history.location.pathname).toBe('/c')
+  })
+
+  test('push and back #1916', () => {
+    const history = createMemoryHistory()
+    history.push('/a')
+    expect(history.location.pathname).toBe('/a')
+    history.push('/b')
+    expect(history.location.pathname).toBe('/b')
+    history.push('/c')
+    expect(history.location.pathname).toBe('/c')
+    history.back()
+    expect(history.location.pathname).toBe('/b')
+    history.push('/d')
+    expect(history.location.pathname).toBe('/d')
+    history.back()
+    expect(history.location.pathname).toBe('/b')
+  })
+})