From 7b60bec096d56ceebd81b3dbcbb2d9a2e3d6c85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabien=20Mauqui=C3=A9?= Date: Fri, 29 Apr 2022 12:39:33 +0200 Subject: [PATCH] set initial memory history key to "default" Documentation states that the initial entry always has key `"default"`. However on memory history this is not the case. We check that the key is `"default"` to set a default behavior when the user clicks a "back" button to go back to home, but arrived at the page from a direct link. This works perfectly in the browser, but failed in the test because the key was not "default" on MemoryRouter. --- packages/history/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/history/index.ts b/packages/history/index.ts index c8cdfc04..1e91e748 100644 --- a/packages/history/index.ts +++ b/packages/history/index.ts @@ -857,13 +857,13 @@ export function createMemoryHistory( options: MemoryHistoryOptions = {} ): MemoryHistory { let { initialEntries = ["/"], initialIndex } = options; - let entries: Location[] = initialEntries.map((entry) => { + let entries: Location[] = initialEntries.map((entry, index) => { let location = readOnly({ pathname: "/", search: "", hash: "", state: null, - key: createKey(), + key: index === 0 ? "default" : createKey(), ...(typeof entry === "string" ? parsePath(entry) : entry), });