Skip to content

Commit 9efa5d1

Browse files
Find the node with router information recursively
1 parent a70d752 commit 9efa5d1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

package/index.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@ const mode = {
99
const linkFiber = require('./linkFiber')(snapShot, mode);
1010
const timeJump = require('./timeJump')(snapShot, mode);
1111

12-
window.addEventListener('message', ({ data: { action, payload } }) => {
13-
//runs automatically twice per second with inspectedElement
12+
let url = '/';
13+
function getRouteURL(node) {
14+
if (node.name === 'Router') {
15+
url = node.state.location.pathname;
16+
}
17+
if (node.children.length >= 1) {
18+
const tempNode = node.children;
19+
for (let index = 0; index < tempNode.length; index += 1) {
20+
getRouteURL(tempNode[index]);
21+
}
22+
}
23+
}
24+
25+
window.addEventListener('message', ({ data: { action, payload } }) => { // runs automatically twice per second with inspectedElement
1426
switch (action) {
1527
case 'jumpToSnap':
1628
timeJump(payload);
29+
getRouteURL(payload);
1730
// Get the pathname from payload and add new entry to browser history
1831
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
19-
if (payload.children[0].state && payload.children[0].state.location) {
20-
const route = payload.children[0].state.location.pathname;
21-
window.history.pushState('', '', route);
22-
}
32+
window.history.pushState('', '', url);
2333
break;
2434
case 'setLock':
2535
mode.locked = payload;

0 commit comments

Comments
 (0)