1

当我在任何点上随机从一个组件移动到另一个组件时,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>

可能是什么原因?我们如何解决它?

4

1 回答 1

0

入住。process.env.BASE_URL_ createWebHistory(process.env.BASE_URL)我有类似的问题,我有一个错字并留下了这样的配置:history:createWebHistory,

于 2021-11-04T23:41:27.580 回答