每天一个神奇bug--路由跳转了但没有完全跳转

59 阅读1分钟

环境

  • "vue": "3.3.9"
  • "vue-router": "4.2.5"

问题描述

点击菜单通过router.push修改路由地址,地址栏改变,但是页面空白

解决方法

给 routerView 添加一个key

<template>
    <router-view v-slot="{ Component, route }" :key="key">
    </router-view>
</template>

<script setup>
...
const route = useRoute();
const key = computed(() => {
  return route.path + Math.random();
});
</script>