javascriptvue.jsionic-frameworkionic4ionic-vue

how to ionic tab close when i switch component in vue ionic?


I am trying to navigate from tabe component to workOrder component. I am using default ionic tabs.

Problem is when I am switching from tab 1 to worOrder component it works perfectly but it also render previous component which is tab component

Here is tab 1 component

enter image description here

But when I choose work order from side menu it also render tab one component

enter image description here

I want to come out of this issue.

Here is side menu which I am using to switch

<template>

 <ion-menu side="start" content-id="menu-content">
    <ion-header>
      <ion-toolbar color="primary">
        <ion-title>{{userInfo.name}}</ion-title>
      </ion-toolbar>
    </ion-header>
    <ion-content id="menu-content">
      <ion-list lines="full">
      
        <ion-item v-for="item in items" :key="item.name">
           <ion-button :router-link="item.href">
          <ion-icon :name="item.icon" slot="start" ></ion-icon>
          <ion-label>{{ item.name }} </ion-label>
           </ion-button>
        </ion-item>
       
      </ion-list>
    </ion-content>
  </ion-menu>
</template>
<style>
.my-custom-menu {
  --width: 500px;
}
</style>

<script>
import { 
  IonContent, 
  IonHeader, 
  IonItem, 
  IonList, 
  IonMenu, 
  IonTitle, 
  IonToolbar,
  IonButton
} from '@ionic/vue';
import { defineComponent } from 'vue';
import { TokenService } from "@/services/token.service";

export default defineComponent({
  components: {
    IonContent, 
    IonHeader, 
    IonItem, 
    IonList, 
    IonMenu, 
    IonButton,

    IonTitle, 
    IonToolbar
  },
  data(){
    return {
       items: [
         { name: 'Home', icon: 'home', href: '/tabs/tab1' },
        { name: 'Work Orders', icon: 'home', href: '/gang-boss-work-orders' },
        { name: 'Log out', icon: 'logout', href: 'logout' }
      ],
       userInfo: TokenService.getUserInfo(),
    }
  },
 beforeMount(){
   console.log(JSON.stringify(this.userInfo))
 }
});
</script>

Here is work order component

<template>
<ion-page>
  <ion-header>
    <ion-toolbar>
      <ion-title>Work Orders</ion-title>
      <ion-buttons slot="start">
        <ion-menu-button auto-hide="false"></ion-menu-button>
      </ion-buttons>
      <ion-buttons slot="primary">
        <ion-button color="secondary" @click="handleSignOut">
          <ion-icon slot="icon-only" :icon="logOut"></ion-icon>
        </ion-button>
      </ion-buttons>
      <ion-buttons slot="primary"> </ion-buttons>
    </ion-toolbar>
  </ion-header>
  <!-- List of Text Items -->
  <ion-list>
    <ion-item v-for="(work_order, index) in this.work_orders" :key="index">
      <ion-label
        >{{ work_order.id }} - {{ work_order.meeting_location }} | Cutting
        Company: {{ work_order.cutting_company_details.staffs.name }}
      </ion-label>
    </ion-item>
  </ion-list>
  </ion-page>
  <side-menu />

</template>

<script>
import { IonItem, IonList, IonLabel } from "@ionic/vue";
import SideMenu from "../SideMenu.vue";
import ApiService from "../../services/api.service";
import { TokenService } from "@/services/token.service";

export default {
  components: {
    IonItem,
    IonList,
    IonLabel,
    SideMenu,
    
  },
  data() {
    return {
      work_orders: null,
    };
  },
  methods: {
    getWorkOrders: function () {
      const boss_id = TokenService.getUserInfo().role_details.id;

      return ApiService.get(`/api/gangBoss/workOrders/view/${boss_id}`).then(
        (response) => {
          this.work_orders = response.data;
          console.log(this.work_orders);
          console.log(response.data);
        }
      );
    },
  },
  mounted() {
    this.getWorkOrders();
  },
};
</script>

router file

import { createRouter, createWebHistory } from '@ionic/vue-router';

import Tabs from '../views/Tabs.vue'
import SignIn from "@/views/Signin.vue";
import Signup from "@/views/Signup.vue";
import { TokenService } from "@/services/token.service";

const routes = [
  {
    path: '/',
    redirect: '/tabs/tab1'
  },
  {
    path: '/gang-boss-work-orders',
    component: () => import('@/views/GangBoss/WorkOrder.vue')
  },
  {
    path: '/tabs/',
    component: Tabs,
    children: [
      {
        path: '',
        redirect: 'tab1'
      },
      {
        path: 'tab1',
        component: () => import('@/views/Tab1.vue')
      },
      {
        path: 'tab2',
        component: () => import('@/views/Tab2.vue')
      },
      {
        path: 'tab3',
        component: () => import('@/views/Tab3.vue')
      },
      
    ]
  },
  {
    path: '/login',
    component: SignIn,
    meta: {
      public: true,
      onlyWhenLoggedOut: true
    }
  },
  {
    path: '/signup',
    component: Signup,
    meta: {
      public: true,
      onlyWhenLoggedOut: true
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  const isPublic = to.matched.some(record => record.meta.public);
  const onlyWhenLoggedOut = to.matched.some(
      record => record.meta.onlyWhenLoggedOut
  );
  const loggedIn = !!TokenService.getToken();

  if (!isPublic && !loggedIn) {
    return next({
      path: "/login",
      query: { redirect: to.fullPath }
    });
  }

  if (loggedIn && onlyWhenLoggedOut) {
    return next("/tabs/tab1");
  }

  next();
});

export default router

Solution

    1. there is no ion-content section on your page
    2. why is ' ' on the bottom of the work order component page?