gpt4 book ai didi

vue.js - 未捕获的类型错误 : Cannot use 'in' operator to search for 'path' in undefined vue router

转载 作者:行者123 更新时间:2023-12-05 02:42:42 28 4
gpt4 key购买 nike

当我在任何一点上随机从一个组件移动到另一个组件时,vue 会给出此错误,然后我无法移动另一个组件。

此错误不在任何特定组件上,它可能发生在任何地方。

错误

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)

这是我的路由器 index.js 文件

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

这就是我在我的组件中使用链接路由器的方式

<ion-item router-link="/search-workers" v-if="userInfo?.role_id == 9" @click="opened()">
Search Worker
</ion-item>

这可能是什么原因呢?我们该如何解决?

最佳答案

检查 createWebHistory(process.env.BASE_URL) 中的 process.env.BASE_URL。我遇到了类似的问题,我有一个错字,并留下了这样的配置:history:createWebHistory,

关于vue.js - 未捕获的类型错误 : Cannot use 'in' operator to search for 'path' in undefined vue router,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67360207/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com