Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs not triggering mounted after user pressed back on his browser

On my vuejs application there is a dashboard, where the user can click a button that send him to /room (router.push("/room");).

When the user arrive on the page, the "mounted" function is triggered and a simple console.log is emited. That works.

mounted() {
    console.log("room mounted");
}

If the user press the "back" button of his browser and go back to the dashboard, he can click the button again to join the room, except this time, the "mounted" function is not triggered.

Is there a way to make this works ?

Thank you.

like image 437
Leeroy521 Avatar asked Oct 15 '22 03:10

Leeroy521


1 Answers

In response to a part of your response to the answer below,

what I'm looking for is when I click again on the button that trigger the router.push("/room"), because when I'm redirected, mounted nor updated` are called.

To solve your problem, you can watch the $route object, by doing

watch: {
  '$route' () {
     // this will be called any time the route changes
   }
},
like image 129
Tony Avatar answered Oct 21 '22 07:10

Tony