在历史模式下从子路由刷新时组件被挂载两次

Component is mounted twice when refreshing from child route in history mode

我在历史模式下使用 vue-router。当我在子路由“/dashboard”上刷新页面时,<ccp/> 组件被安装了两次。在 ccp 组件中,我正在控制台登录创建和安装的挂钩。我看到每个控制台输出两次。有什么想法吗?在此先感谢您的关注!

编辑:在初始应用程序加载时,<ccp/> 仅创建和安装一次。

代码如下:

App.vue:

<template>
    <div v-show="isConnected">
      <ccp/>
      <router-view/>
    </div>
</template>

<script>
     // blah blah blah - doing stuff and then pushing route to /dashboard
    return this.$router.push({name: "dashboard"});
</script>

router.js

export default new Router({
mode: "history",
routes: [
// DEFAULT ROUTE
{
  path: "/",
  name: "root",
  alias: store.getters.isDemoMode ? "/demo" : "/app" // isDemoMode is false for this test however I wanted to show the alias config in case that is part of the problem.
},

{
  path: "/demo",
  name: "demo",
  component: Demo
},
{
  path: "/app",
  name: "app",
  component: App,
  children: [
    {
      path: "/dashboard",
      name: "dashboard",
      component: Dashboard
    }
  ]
 }
})

它被安装了两次,可能是因为 App 组件也是您路由的一部分。您名为 "app" 的路由正在再次安装 App。