New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fix for detecting client side hash change #5

Merged
merged 1 commit into from Nov 3, 2017
Jump to file or symbol
Failed to load files and symbols.
+53 −4
Diff settings

Always

Just for now

@@ -3,16 +3,21 @@
*/
const isOnlyHrefHashChange = (a, b) => {
if (a === b) {
return true;
}
if (!a || !b) {
return false;
}
if (!a.includes('#') || !b.includes('#')) {
return false;
}
// If there is a hash, but the string before the hash matches, then it is a
// hash only change. If the hash values are mismatching, or the same, it does
// not matter because the browser will deal with that.
if (a.split('#')[0] === b.split('#')[0]) {
return true;
}
// TODO: check for relative href
return false;
};
@@ -0,0 +1,44 @@
import test from 'ava';
import 'babel-core/register';
import isOnlyHrefHashChange from 'redux-router-kit/src/utils/isOnlyHrefHashChange';
test('will return `false` if the first or second location do not exist', t => {
const locationA = undefined;
const locationB = undefined;
const result = isOnlyHrefHashChange(locationA, locationB);
const expected = false;
t.is(result, expected);
});
test('will return `false` if the first or second location does not contain a hash', t => {
const locationA = 'http://www.localhost:8000/app/explore';
const locationB = 'http://www.localhost:8000/app/explore';
const result = isOnlyHrefHashChange(locationA, locationB);
const expected = false;
t.is(result, expected);
});
test('will return `true` if both strings contain a hash and the base values are the same', t => {
const locationA = 'http://www.localhost:8000/app/explore/#/hello-world';
const locationB = 'http://www.localhost:8000/app/explore/#/hello-world-part-2';
const result = isOnlyHrefHashChange(locationA, locationB);
const expected = true;
t.is(result, expected);
});
test('will return `false` if both strings contain a hash and the base values are different', t => {
const locationA = 'http://www.localhost:8000/app/contact-us/#/hello-world';
const locationB = 'http://www.localhost:8000/app/explore/#/hello-world';
const result = isOnlyHrefHashChange(locationA, locationB);
const expected = false;
t.is(result, expected);
});
ProTip! Use n and p to navigate between commits in a pull request.