when I am randomly moving from one component to another on any point vue gives this error and then i can not move another component.
This error is not on any specific component it can happen anywhere.
error
Uncaught TypeError: Cannot use 'in' operator to search for 'path' in undefined
at Object.resolve (vue-router.esm-bundler.js?6c02:2728)
at matchView (index.esm.js?bec5:446)
at Array.find (<anonymous>)
at findViewItemByPath (index.esm.js?bec5:464)
at Object.findViewItemByRouteInfo (index.esm.js?bec5:424)
at Object.canStart (index.js?8a30:805)
at eval (ion-app_8.entry.js?49af:707)
at canStart (swipe-back-53c5a7dd.js?05d4:8)
at pointerDown (index-f49d994d.js?14e6:251)
Here is my router index.js 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: '/search-workers',
component: () => import('@/views/SearchWorker.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
This is how i am using link router in my components
<ion-item router-link="/search-workers" v-if="userInfo?.role_id == 9" @click="opened()">
Search Worker
</ion-item>
What could be the reason of it? How we can resolve it?
to='/'
torouter-link
– Lucarne