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

Viewed 5952

I am using vue-router in history mode. When I am on on child route "/dashboard" and I refresh the page, the <ccp/> component is mounted twice. In the ccp component I am console logging in the created and mounted hook. I see that console output twice for each one. Any thoughts? Thanks in advance for looking!

Edit: On initial app load, <ccp/> is created and mounted only once.

Here's the code:

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
    }
  ]
 }
})
1 Answers

It's mounted twice likely due to the App component also being part of your route. Your route named "app" is mounting App again.

Related