diff --git a/modules/LocationUtils.js b/modules/LocationUtils.js index bc3d50c85..c4a767c3d 100644 --- a/modules/LocationUtils.js +++ b/modules/LocationUtils.js @@ -68,9 +68,9 @@ export const createLocation = (path, state, key, currentLocation) => { return location } -export const locationsAreEqual = (a, b) => +export const locationsAreEqual = (a, b, ignoreKey = false) => a.pathname === b.pathname && a.search === b.search && a.hash === b.hash && - a.key === b.key && + (ignoreKey || a.key === b.key) && valueEqual(a.state, b.state) diff --git a/modules/createBrowserHistory.js b/modules/createBrowserHistory.js index 2ac82f58b..0d58eecb8 100644 --- a/modules/createBrowserHistory.js +++ b/modules/createBrowserHistory.js @@ -1,6 +1,6 @@ import warning from "warning" import invariant from "invariant" -import { createLocation } from "./LocationUtils" +import { createLocation, locationsAreEqual } from "./LocationUtils" import { addLeadingSlash, stripTrailingSlash, @@ -165,7 +165,7 @@ const createBrowserHistory = (props = {}) => { const action = "PUSH" const location = createLocation(path, state, createKey(), history.location) - if (createPath(location) === createPath(history.location)) { + if (locationsAreEqual(location, history.location, true)) { replace(path, state) return } diff --git a/modules/createMemoryHistory.js b/modules/createMemoryHistory.js index 7afcab952..789b8454b 100644 --- a/modules/createMemoryHistory.js +++ b/modules/createMemoryHistory.js @@ -1,6 +1,6 @@ import warning from "warning" import { createPath } from "./PathUtils" -import { createLocation } from "./LocationUtils" +import { createLocation, locationsAreEqual } from "./LocationUtils" import createTransitionManager from "./createTransitionManager" const clamp = (n, lowerBound, upperBound) => @@ -58,7 +58,7 @@ const createMemoryHistory = (props = {}) => { const action = "PUSH" const location = createLocation(path, state, createKey(), history.location) - if (createPath(location) === createPath(history.location)) { + if (locationsAreEqual(location, history.location, true)) { replace(path, state) return }