Skip to content

Commit a99cb2c

Browse files
[FIX] Handle hash change in url
1 parent 42c02b5 commit a99cb2c

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/hash-to-query/index.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ module.exports = {
1212
if (type === 'body') {
1313
return `
1414
<script type='text/javascript'>
15-
var hash = window.location.hash;
16-
if (hash && hash.length > 1) {
17-
var pathName = window.location.pathname;
18-
if (pathName.indexOf('/methods/') === -1 &&
19-
pathName.indexOf('/properties/') === -1 &&
20-
pathName.indexOf('/events/') === -1) {
21-
var type = hash.slice(1, hash.indexOf('_'));
22-
var name = hash.slice(hash.indexOf('_') + 1, hash.length);
23-
var anchor = '?anchor=' + name + '&show=inherited,protected,private,deprecated';
24-
var newPath = pathName;
25-
if (type === 'method') {
26-
newPath = pathName + '/methods/' + name;
27-
} else if (type === 'property') {
28-
newPath = pathName + '/properties/' + name;
29-
} else if (type === 'event') {
30-
newPath = pathName + '/events/' + name;
15+
function hashToQuery() {
16+
var hash = window.location.hash;
17+
if (hash && hash.length > 1) {
18+
var pathName = window.location.pathname;
19+
if (pathName.indexOf('/methods/') === -1 &&
20+
pathName.indexOf('/properties/') === -1 &&
21+
pathName.indexOf('/events/') === -1) {
22+
var type = hash.slice(1, hash.indexOf('_'));
23+
var name = hash.slice(hash.indexOf('_') + 1, hash.length);
24+
var anchor = '?anchor=' + name + '&show=inherited,protected,private,deprecated';
25+
var newPath = pathName;
26+
if (type === 'method') {
27+
newPath = pathName + '/methods/' + name;
28+
} else if (type === 'property') {
29+
newPath = pathName + '/properties/' + name;
30+
} else if (type === 'event') {
31+
newPath = pathName + '/events/' + name;
32+
}
33+
window.location.href = window.location.origin + newPath + anchor;
3134
}
32-
window.location.href = window.location.origin + newPath + anchor;
3335
}
3436
}
37+
hashToQuery()
38+
window.onhashchange = hashToQuery;
3539
</script>
3640
`
3741
}

0 commit comments

Comments
 (0)