Skip to content

Commit 93b1325

Browse files
authored
Merge pull request #12 from oslabs-beta/rajeeb/fix/route-nesting
Router: Recursively find the node with route information
2 parents 53275aa + c6f6ce2 commit 93b1325

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

package/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,25 @@ 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+
function getRouteURL(node) {
13+
if (node.name === 'Router') {
14+
return node.state.location.pathname;
15+
}
16+
if (node.children.length >= 1) {
17+
const tempNode = node.children;
18+
for (let index = 0; index < tempNode.length; index += 1) {
19+
return getRouteURL(tempNode[index]);
20+
}
21+
}
22+
}
23+
24+
window.addEventListener('message', ({ data: { action, payload } }) => { // runs automatically twice per second with inspectedElement
1425
switch (action) {
1526
case 'jumpToSnap':
1627
timeJump(payload);
1728
// Get the pathname from payload and add new entry to browser history
1829
// 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-
}
30+
window.history.pushState('', '', getRouteURL(payload));
2331
break;
2432
case 'setLock':
2533
mode.locked = payload;

0 commit comments

Comments
 (0)