Skip to content

Commit

Permalink
lastMatch should depend on isExact as well (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
syadykin authored Mar 14, 2020
1 parent 66eda0c commit 16d4327
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const createSelectors = (structure) => {
}
lastPathname = pathname
const match = matchPath(pathname, path)
if (!match || !lastMatch || match.url !== lastMatch.url) {
if (!match || !lastMatch || match.url !== lastMatch.url || match.isExact !== lastMatch.isExact) {
lastMatch = match
}

Expand Down
13 changes: 8 additions & 5 deletions test/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,14 @@ describe("selectors", () => {

it("does not update if the match is the same", () => {
const matchSelector = createMatchSelector("/")
store.dispatch(push('test1'))
const match = matchSelector(store.getState())
store.dispatch(push('test2'))
const expectedMatch = matchSelector(store.getState())
expect(match).toBe(expectedMatch)
const match1 = matchSelector(store.getState())
store.dispatch(push('/test1'))
const match2 = matchSelector(store.getState())
store.dispatch(push('/test2'))
const match3 = matchSelector(store.getState())
expect(match1).not.toBe(match2)
expect(match1).not.toBe(match3)
expect(match2).toEqual(match3)
})

it("updates if the match is different", () => {
Expand Down

0 comments on commit 16d4327

Please sign in to comment.