页面刷新url返回默认页面问题解决

app.vue

onMounted(async () => {
     // 监听浏览器的beforeunload事件
     window.addEventListener('beforeunload', (event) => {
      
      // 如果条件满足(例如当前不是默认页面时),重定向到默认页
      if (route.path !== '/') {
        router.push('/');
      }
    });
 
    // 组件卸载前移除事件监听,避免内存泄露
    onUnmounted(() => {
      window.removeEventListener('beforeunload', () => {});
    });

})

你可能感兴趣的:(前端,java,javascript)