Skip to content
This repository was archived by the owner on Mar 15, 2023. It is now read-only.

Commit 40ec566

Browse files
netsvetochArtem Netsvetaev
andauthored
fix routing (#10)
Co-authored-by: Artem Netsvetaev <physphile@vk.com>
1 parent 67b740e commit 40ec566

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/components/DesktopMenu.vue

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
v-for="(item, i) in items"
55
:key="item.title"
66
v-bind="item"
7-
:active="active === i"
7+
:active="pathname.startsWith(item.path)"
88
@click="() => navigate(i)"
99
/>
1010
</menu>
@@ -21,27 +21,30 @@ export default {
2121
data() {
2222
return {
2323
items,
24-
active: items.reduce(
25-
(acc, cur, i) =>
26-
window.location.pathname.startsWith(cur.path) ? i : acc,
27-
0,
28-
),
24+
pathname: window.location.pathname,
2925
};
3026
},
3127
methods: {
3228
navigate(i) {
33-
this.active = i;
34-
document.dispatchEvent(
35-
new CustomEvent('change-page', {
36-
detail: {
37-
path: items[i].path,
38-
},
39-
}),
40-
);
4129
singleSpa.navigateToUrl(items[i].path);
4230
},
31+
beforeRoutingEventHandler() {
32+
this.pathname = window.location.pathname;
33+
},
4334
},
4435
components: { DesktopMenuItem },
36+
mounted() {
37+
window.addEventListener(
38+
'single-spa:before-routing-event',
39+
this.beforeRoutingEventHandler,
40+
);
41+
},
42+
unmounted() {
43+
window.removeEventListener(
44+
'single-spa:before-routing-event',
45+
this.beforeRoutingEventHandler,
46+
);
47+
},
4548
};
4649
</script>
4750
<style scoped>

0 commit comments

Comments
 (0)