When navigating back from a child route in history mode, the component is erroneously mounted twice

I have encountered an issue while using vue-router in history mode. When I am on the child route "/dashboard" and refresh the page, the <ccp/> component seems to be mounted twice. The ccp component has console logging in both the created and mounted hooks, resulting in the console output appearing twice for each hook. Any ideas or suggestions would be greatly appreciated. Thank you in advance!

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

Below is the code snippet:

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

Answer №1

The reason for it being mounted twice is probably because the App component is included in your route configuration. The route named "app" is causing the App to be mounted again.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Problem encountered while using AJAX to load a PHP script, triggered by an onclick event;

My expertise lies in HTML, CSS, JavaScript, and PHP. However, I find myself lacking in knowledge when it comes to jQuery and Ajax. While I work on web design projects involving bars and nightclubs that prioritize style over performance, my current job dema ...

I am interested in embedding several miniature images of solar panels within a polygon shape on Google Maps

[insert image of a polygon here and multiple images of solar panels inside the polygon][1] I need to include multiple small images of solar panels inside a polygon on Google Maps using the @react-google-maps/api package import React from "react" ...

Eliminate any line breaks from the information retrieved from the node event process.stdin.on("data") function

I've been struggling to find a solution to this issue. No matter what approach I take, I can't seem to remove the new line character at the end of my string. Take a look at my code below. I attempted using str.replace() in an effort to eliminate ...

Pass identical data to the view using both POST and GET methods in a node.js / Express.js application

At first, I attempted to utilize the router.post and router.get methods separately in my code. But then I made the decision to use router.all, and within the same function split POST and GET calls, using two res.render functions along with a common object ...

Locate and retrieve user data from MongoDB

Let me provide some context. I am transmitting a post along with the username and what he shared with me is shown in the log. console.log(req.body.username); // 'username' My question is, how can I utilize mongodb to locate and display a user w ...

What is the best way to bring in a service as a singleton class using System.js?

I have a unique Singleton-Class FooService that is loaded through a special import-map. My goal is to efficiently await its loading and then utilize it in different asynchronous functions as shown below: declare global { interface Window { System: Sy ...

Searching for data in Node.js using Mongoose and dates

I'm in search of a way to execute a specific query with mongoose. In my mongodb database, I have data structured like this: "startDateTime" : ISODate("2017-03-22T00:00:00.000Z"), "endDateTime" : ISODate("2017-03-27T00:00:00.000Z"), My goal is to r ...

Triggering a sweet alert on a mouse click

Here is a code snippet I found on . It shows an alert box that doesn't disappear when clicked outside of it. swal({ title: "Are you sure?", text: "You will not be able to recover this imaginary file!", type: "warning", showCancelButton: true, ...

Activate jQuery function upon clicking a bootstrap tab

When I click on a Bootstrap tab, I want to trigger an AJAX function. Here is the HTML code: <li><a href="#upotrebljeni" data-toggle="tab">Upotrebljeni resursi</a></li> The jQuery AJAX function looks like this: $('a #upotreb ...

What is the process of uploading a file from a Vue.js app to the local public disk in Laravel?

Hello there, I am looking to upload a file from a Vue.js app to the local public directory of Laravel and only store the unique name in MySQL upon form submission. However, I am unsure how to achieve this using JavaScript. // Template Tag <input type= ...

unique map customized in a separate browser window

Attempting to complete the code provided here but encountering issues as a novice in java-scripting. It seems like the map is not loading correctly. A new tab and text are generated when DIV is created. Seeking assistance on how to open a custom map in a ...

exchanging the positions of two animated flipdivs

Hey there! I'm facing a little challenge with my two divs (let's call them div1 and div2). One of them has a flip animation on hover, while the other flips on toggle click. My goal is to swap these two divs by dragging and dropping them. I' ...

"Hidden panels in Sencha Touch only respond to show() and hide() methods after a resize event

Check out this demonstration of a Sencha Touch app by visiting this link. The button located in the bottom-left corner is supposed to show or hide the menu panel on top of the "Location info goes here" bar, but it seems to be functioning in an unexpected m ...

What is the proper way to convert nil to JSON as nil, without representing it as an empty value?

I'm facing an issue in my controller/action where some values turn out to be nil: def my_action @var1 = get_boolean_value || nil @var2 = get_int_value || nil @var3 = get_string_value || nil # there are many more values, any of them might be ...

Unable to alter the state through the URL bar using ui-router

I am facing an issue where I get redirected to the home state whenever I try to directly access a URL like mysite.com/#!/about. My menu with ui-sref links is functioning correctly, but when it comes to nested states, I encounter problems switching betwee ...

having trouble retrieving 200 status code from Angular server response

Objective: I need to make certain changes to the record locally if the server responds with a 200 code. Problem: I am unable to retrieve the response code or access the 'message' attribute. This is the server response I receive from the HTTP ca ...

Problem encountered when attempting to pass data from parent to child component

While using Vuu.js, I encountered an issue with passing a value from parent to child component. Initially, I had it working perfectly with a provided example. However, as soon as I tried changing the name, the functionality broke. I'm struggling to un ...

Incorporating Imported Modules into the Final Build of a Typescript Project

In my Visual Studio Code Typescript project, I have set up some basic configurations and used npm to download libraries. One of the main files in my project is main.ts which includes the following code: import ApexCharts from 'apexcharts' var c ...

Get your hands on Excel by utilizing the power of Ajax and Flask

I'm attempting to download an excel file from Flask using an Ajax call. The response code shows as 200, but the excel file is not downloading. The error messages I am receiving are as follows: Ajax Request : $("#genExcel").on("click", function() { ...

When attempting to assign a 'string' type to the @Input property, I am receiving an error stating that it is not assignable to the 'PostCard Layout' type

Encountering an issue The error message 'Type 'string' is not assignable to type 'PostCard Layout'' is being displayed A parent component named page-blog.component.html is responsible for defining the class styles and passi ...