Skip to content

Commit bdab3d8

Browse files
committed
[fixed] Compare query by string value
1 parent c43fb61 commit bdab3d8

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

modules/__tests__/isActive-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('isActive', function () {
2222
describe('with no query', function () {
2323
it('is active', function (done) {
2424
React.render((
25-
<Router history={createHistory('/home')}>
25+
<Router history={createHistory('/home?the=query')}>
2626
<Route path="/home" />
2727
</Router>
2828
), node, function () {
@@ -45,6 +45,19 @@ describe('isActive', function () {
4545
})
4646
})
4747

48+
describe('with a query that also matches by value, but not by type', function () {
49+
it('is active', function (done) {
50+
React.render((
51+
<Router history={createHistory('/home?the=query&n=2&show=false')}>
52+
<Route path="/home" />
53+
</Router>
54+
), node, function () {
55+
expect(this.history.isActive('/home', { the: 'query', n: 2, show: false })).toBe(true)
56+
done()
57+
})
58+
})
59+
})
60+
4861
describe('with a query that does not match', function () {
4962
it('is not active', function (done) {
5063
React.render((

modules/isActive.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import { matchPattern } from './PatternUtils'
2-
import deepEqual from 'deep-equal'
2+
3+
function deepEqual(a, b) {
4+
if (a == b)
5+
return true
6+
7+
if (a == null || b == null)
8+
return false
9+
10+
if (Array.isArray(a)) {
11+
return Array.isArray(b) && a.length === b.length && a.every(function (item, index) {
12+
return deepEqual(item, b[index])
13+
})
14+
}
15+
16+
if (typeof a === 'object') {
17+
for (let p in a)
18+
if (a.hasOwnProperty(p) && (!b.hasOwnProperty(p) || !deepEqual(a[p], b[p])))
19+
return false
20+
21+
return true
22+
}
23+
24+
return String(a) === String(b)
25+
}
326

427
function paramsAreActive(paramNames, paramValues, activeParams) {
528
return paramNames.every(function (paramName, index) {
@@ -11,10 +34,6 @@ function getMatchingRoute(pathname, activeRoutes, activeParams) {
1134
let route, pattern, basename = ''
1235
for (let i = 0, len = activeRoutes.length; i < len; ++i) {
1336
route = activeRoutes[i]
14-
15-
//if (!route.path)
16-
// return false
17-
1837
pattern = route.path || ''
1938

2039
if (pattern.charAt(0) !== '/')

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
],
2626
"license": "MIT",
2727
"dependencies": {
28-
"deep-equal": "^1.0.0",
2928
"history": "1.12.1",
3029
"invariant": "^2.0.0",
3130
"warning": "^2.0.0"

0 commit comments

Comments
 (0)