Skip to content

Commit f343fdf

Browse files
authored
Merge pull request #224 from amansinghbais/import/#122
Implemented: Page Selection Persistence for Import App with Side Navigation(#122)
2 parents c466e37 + 387de76 commit f343fdf

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

src/components/Menu.vue

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<ion-menu-toggle auto-hide="false" v-for="(p, i) in appPages" :key="i">
1212
<ion-item
1313
button
14-
@click="selectedIndex = i"
1514
router-direction="root"
1615
:router-link="p.url"
1716
class="hydrated"
@@ -51,11 +50,12 @@ import {
5150
IonTitle,
5251
IonToolbar,
5352
} from "@ionic/vue";
54-
import { defineComponent, ref } from "vue";
53+
import { computed, defineComponent } from "vue";
5554
import { mapGetters } from "vuex";
5655
5756
import { albumsOutline, bookmarkOutline, settings, calendar } from "ionicons/icons";
5857
import { useStore } from "@/store";
58+
import { useRouter } from "vue-router";
5959
6060
export default defineComponent({
6161
name: "Menu",
@@ -73,48 +73,35 @@ export default defineComponent({
7373
IonTitle,
7474
IonToolbar
7575
},
76-
created() {
77-
// When open any specific page it should show that page selected
78-
// TODO Find a better way
79-
this.selectedIndex = this.appPages.findIndex((page) => {
80-
return page.url === this.$router.currentRoute.value.path;
81-
})
82-
},
8376
computed: {
8477
...mapGetters({
8578
isUserAuthenticated: 'user/isUserAuthenticated',
8679
instanceUrl: 'user/getInstanceUrl',
8780
userProfile: 'user/getUserProfile'
8881
})
8982
},
90-
watch:{
91-
$route (to) {
92-
// When logout and login it should point to Oth index
93-
// TODO Find a better way
94-
if (to.path === '/login') {
95-
this.selectedIndex = 0;
96-
}
97-
},
98-
},
9983
setup() {
10084
const store = useStore();
101-
const selectedIndex = ref(0);
85+
const router = useRouter();
10286
const appPages = [
10387
{
10488
title: "Inventory",
10589
url: "/inventory",
90+
childRoutes: ["/inventory-review"],
10691
iosIcon: albumsOutline,
10792
mdIcon: albumsOutline
10893
},
10994
{
11095
title: "Purchase order",
11196
url: "/purchase-order",
97+
childRoutes: ["/purchase-order-review"],
11298
iosIcon: calendar,
11399
mdIcon: calendar
114100
},
115101
{
116102
title: "Saved Mappings",
117103
url: "/saved-mappings",
104+
childRoutes: ["/mapping/"],
118105
iosIcon: bookmarkOutline,
119106
mdIcon: bookmarkOutline
120107
},
@@ -123,8 +110,14 @@ export default defineComponent({
123110
url: "/settings",
124111
iosIcon: settings,
125112
mdIcon: settings,
126-
},
113+
}
127114
];
115+
116+
const selectedIndex = computed(() => {
117+
const path = router.currentRoute.value.path
118+
return appPages.findIndex((screen) => screen.url === path || screen.childRoutes?.includes(path) || screen.childRoutes?.some((route) => path.includes(route)))
119+
})
120+
128121
return {
129122
selectedIndex,
130123
appPages,
@@ -133,7 +126,7 @@ export default defineComponent({
133126
settings,
134127
store
135128
};
136-
},
129+
}
137130
});
138131
</script>
139132
<style scoped>

0 commit comments

Comments
 (0)