11
11
<ion-menu-toggle auto-hide =" false" v-for =" (p, i) in appPages" :key =" i" >
12
12
<ion-item
13
13
button
14
- @click =" selectedIndex = i"
15
14
router-direction =" root"
16
15
:router-link =" p.url"
17
16
class =" hydrated"
@@ -51,11 +50,12 @@ import {
51
50
IonTitle ,
52
51
IonToolbar ,
53
52
} from " @ionic/vue" ;
54
- import { defineComponent , ref } from " vue" ;
53
+ import { computed , defineComponent } from " vue" ;
55
54
import { mapGetters } from " vuex" ;
56
55
57
56
import { albumsOutline , bookmarkOutline , settings , calendar } from " ionicons/icons" ;
58
57
import { useStore } from " @/store" ;
58
+ import { useRouter } from " vue-router" ;
59
59
60
60
export default defineComponent ({
61
61
name: " Menu" ,
@@ -73,48 +73,35 @@ export default defineComponent({
73
73
IonTitle ,
74
74
IonToolbar
75
75
},
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
- },
83
76
computed: {
84
77
... mapGetters ({
85
78
isUserAuthenticated: ' user/isUserAuthenticated' ,
86
79
instanceUrl: ' user/getInstanceUrl' ,
87
80
userProfile: ' user/getUserProfile'
88
81
})
89
82
},
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
- },
99
83
setup() {
100
84
const store = useStore ();
101
- const selectedIndex = ref ( 0 );
85
+ const router = useRouter ( );
102
86
const appPages = [
103
87
{
104
88
title: " Inventory" ,
105
89
url: " /inventory" ,
90
+ childRoutes: [" /inventory-review" ],
106
91
iosIcon: albumsOutline ,
107
92
mdIcon: albumsOutline
108
93
},
109
94
{
110
95
title: " Purchase order" ,
111
96
url: " /purchase-order" ,
97
+ childRoutes: [" /purchase-order-review" ],
112
98
iosIcon: calendar ,
113
99
mdIcon: calendar
114
100
},
115
101
{
116
102
title: " Saved Mappings" ,
117
103
url: " /saved-mappings" ,
104
+ childRoutes: [" /mapping/" ],
118
105
iosIcon: bookmarkOutline ,
119
106
mdIcon: bookmarkOutline
120
107
},
@@ -123,8 +110,14 @@ export default defineComponent({
123
110
url: " /settings" ,
124
111
iosIcon: settings ,
125
112
mdIcon: settings ,
126
- },
113
+ }
127
114
];
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
+
128
121
return {
129
122
selectedIndex ,
130
123
appPages ,
@@ -133,7 +126,7 @@ export default defineComponent({
133
126
settings ,
134
127
store
135
128
};
136
- },
129
+ }
137
130
});
138
131
</script >
139
132
<style scoped>
0 commit comments