Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 3b48c44

Browse files
author
William Johnson
authored
Merge pull request #22 from segmentio/fix/page-defaults-search
update page defaults search method
2 parents ca1f25f + 831c2c5 commit 3b48c44

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/pageDefaults.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function pageDefaults() {
2020
return {
2121
path: canonicalPath(),
2222
referrer: document.referrer,
23-
search: location.search,
23+
search: searchPath(),
2424
title: document.title,
2525
url: canonicalUrl(location.search)
2626
};
@@ -55,6 +55,21 @@ function canonicalUrl(search) {
5555
return i === -1 ? url : url.slice(0, i);
5656
}
5757

58+
/**
59+
* Return the search path for the page
60+
* This is preferable to window.location.search because SPAs
61+
* can have a # in the url which will include the query param in
62+
* the hash
63+
*
64+
* @return {string}
65+
*/
66+
67+
function searchPath() {
68+
var url = window.location.href;
69+
var u = url.indexOf('?');
70+
return u === -1 ? '' : url.slice(u, -1);
71+
}
72+
5873
/*
5974
* Exports.
6075
*/

0 commit comments

Comments
 (0)