Skip to content

Commit

Permalink
Use shared compare function.
Browse files Browse the repository at this point in the history
  • Loading branch information
guidobouman committed Jan 11, 2018
1 parent 37fa51a commit 0796a45
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/LocationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions modules/createBrowserHistory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import warning from "warning"
import invariant from "invariant"
import { createLocation } from "./LocationUtils"
import { createLocation, locationsAreEqual } from "./LocationUtils"
import {
addLeadingSlash,
stripTrailingSlash,
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions modules/createMemoryHistory.js
Original file line number Diff line number Diff line change
@@ -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) =>
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0796a45

Please sign in to comment.