Skip to content

Commit

Permalink
Merge pull request #275 from ymaheshwari1/fix/routes
Browse files Browse the repository at this point in the history
Fixed: routing in the app to use the tabs/ pattern when using ion-tab-bar
  • Loading branch information
ymaheshwari1 authored Apr 19, 2024
2 parents 15b334f + 5361741 commit a856a05
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 45 deletions.
15 changes: 1 addition & 14 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
<ion-content>
<ion-router-outlet />
</ion-content>
<ion-footer v-if="showFooter">
<ion-toolbar>
<tab-bar />
</ion-toolbar>
</ion-footer>
</ion-page>
</ion-app>
</template>

<script lang="ts">
import { IonApp, IonRouterOutlet, IonPage, IonFooter, IonToolbar, IonContent } from '@ionic/vue';
import { IonApp, IonRouterOutlet, IonPage, IonContent } from '@ionic/vue';
import { defineComponent } from 'vue';
import { loadingController } from '@ionic/vue';
import emitter from "@/event-bus"
import TabBar from "./components/TabBar.vue"
import { mapGetters, useStore } from 'vuex';
import { initialise, resetConfig } from '@/adapter'
import { useRouter } from 'vue-router';
Expand All @@ -30,9 +24,6 @@ export default defineComponent({
IonApp,
IonRouterOutlet,
IonPage,
IonFooter,
IonToolbar,
TabBar,
IonContent
},
data() {
Expand Down Expand Up @@ -106,10 +97,6 @@ export default defineComponent({
resetConfig()
},
computed: {
showFooter () {
if (['/settings', '/search', '/upload'].includes(this.$route.path)) return true
return false
},
...mapGetters({
userToken: 'user/getUserToken',
instanceUrl: 'user/getInstanceUrl',
Expand Down
6 changes: 3 additions & 3 deletions src/components/TabBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<ion-tabs>
<ion-router-outlet></ion-router-outlet>
<ion-tab-bar slot="bottom" ref="tabs">
<ion-tab-button v-if="hasPermission(Actions.APP_SEARCH_VIEW)" tab="search" href="/search">
<ion-tab-button v-if="hasPermission(Actions.APP_SEARCH_VIEW)" tab="search" href="/tabs/search">
<ion-icon :icon="search" />
<ion-label>{{ $t("Search") }}</ion-label>
</ion-tab-button>
<ion-tab-button v-if="hasPermission(Actions.APP_UPLOAD_VIEW)" tab="upload" href="/upload">
<ion-tab-button v-if="hasPermission(Actions.APP_UPLOAD_VIEW)" tab="upload" href="/tabs/upload">
<ion-icon :icon="cloudUpload" />
<ion-label>{{ $t("Upload") }}</ion-label>
</ion-tab-button>
<ion-tab-button tab="settings" href="/settings">
<ion-tab-button tab="settings" href="/tabs/settings">
<ion-icon :icon="settings" />
<ion-label>{{ $t("Settings") }}</ion-label>
</ion-tab-button>
Expand Down
55 changes: 30 additions & 25 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { createRouter, createWebHistory } from "@ionic/vue-router";
import { RouteRecordRaw } from "vue-router";
import Upload from "@/views/Upload.vue";
import Settings from "@/views/Settings.vue";
import store from "@/store";
import Search from "@/views/Search.vue";
import Count from "@/views/count.vue";
import { hasPermission } from '@/authorization';
import { showToast } from '@/utils'
import { translate } from '@/i18n'
import TabBar from "@/components/TabBar.vue";

import 'vue-router'
import { DxpLogin, useAuthStore } from '@hotwax/dxp-components';
Expand Down Expand Up @@ -43,24 +41,40 @@ const loginGuard = (to: any, from: any, next: any) => {
const routes: Array<RouteRecordRaw> = [
{
path: "/",
redirect: "/search",
redirect: "/tabs/search",
},
{
path: "/upload",
name: "upload",
component: Upload,
path: '/tabs',
component: TabBar,
children: [
{
path: '',
redirect: '/search'
},
{
path: 'search',
component: () => import('@/views/Search.vue'),
meta: {
permissionId: "APP_SEARCH_VIEW"
}
},
{
path: 'upload',
component: () => import('@/views/Upload.vue'),
meta: {
permissionId: "APP_UPLOAD_VIEW"
}
},
{
path: 'settings',
component: () => import('@/views/Settings.vue')
},
],
beforeEnter: authGuard,
meta: {
permissionId: "APP_UPLOAD_VIEW"
permissionId: ""
}
},
{

path: "/settings",
name: "Settings",
component: Settings,
beforeEnter: authGuard
},
{
path: "/count/:sku",
name: "Count",
Expand All @@ -76,15 +90,6 @@ const routes: Array<RouteRecordRaw> = [
name: 'Login',
component: DxpLogin,
beforeEnter: loginGuard
},
{
path: '/search',
name: 'Search',
component: Search,
beforeEnter: authGuard,
meta: {
permissionId: "APP_SEARCH_VIEW"
}
}
];

Expand All @@ -97,7 +102,7 @@ router.beforeEach((to, from) => {
if (to.meta.permissionId && !hasPermission(to.meta.permissionId)) {
let redirectToPath = from.path;
// If the user has navigated from Login page or if it is page load, redirect user to settings page without showing any toast
if (redirectToPath == "/login" || redirectToPath == "/") redirectToPath = "/settings";
if (redirectToPath == "/login" || redirectToPath == "/") redirectToPath = "/tabs/settings";
else {
showToast(translate('You do not have permission to access this page'));
}
Expand Down
6 changes: 3 additions & 3 deletions src/views/count.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@
text: translate('View'),
role: 'view',
handler: () => {
this.router.push('/upload')
this.router.push('/tabs/upload')
}
}])
this.router.push('/search')
this.router.push('/tabs/search')
} else {
showToast(translate("Enter the stock count for the product"))
}
Expand Down Expand Up @@ -386,7 +386,7 @@
// removing after updation
delete this.product.varianceQuantity;
delete this.product.varianceReasonId
this.router.push('/search')
this.router.push('/tabs/search')
},
},
setup() {
Expand Down

0 comments on commit a856a05

Please sign in to comment.