Is there a way to prompt Vue Router to refresh my page while attempting to navigate within the present location?

I currently have my project structured in the following way:

  • Views
    • Home.vue
    • Classroom.vue
  • App.vue

Within the Home.vue file, I display the content and a login form. Essentially, users must submit their login information, and if correct, the isAuth variable is set to true. Subsequently, the form is hidden, revealing the content (a list of classrooms).

<div v-if="isAuth" @click="goToClassroomView"> List of classrooms </div>
<div v-if="!isAuth"&glt; Here is the login form... </div>

Within the App.vue file, I have an app-bar and main section with a router-view containing a logout function.

<v-app-bar app color="#2196f3">
    <v-btn @click="logout()">logout</logout>
</v-app-bar>

<v-main class="white">
      <router-view></router-view> //Either Home.vue or Classroom.vue
</v-main>

Here is the logout function defined inside the App.vue:

 logout() {
        this.$store.dispatch('LOGOUT')
        .then(() => {
          this.$router.push('/') //navigate to home.vue
        })
      }

My current issue arises when I logout while on the home page. The user successfully logs out, but the page remains empty as the list of classrooms is tied to the isAuth variable located in Home.vue, making it inaccessible from App.vue.

Is there a way to either reload the page while on the Home page or access the isAuth variable from App.vue so that upon logging out from the home page, the list of classrooms disappears, and the login form reappears?

Answer №1

To implement a more efficient approach, consider updating the isAuth variable to the vuex store state. By modifying the LOGOUT action, you can set the isAuth state to false.

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

Utilizing the keyword 'this' within a function of a JavaScript class that is invoked with the .map method

I am working with the RegisterUser class which contains various methods and properties: class RegisterUser { constructor(username, password, ispublic){ this.username = username; this.password = password; this.ispublic = ispublic; this.id ...

Execute Javascript Code Once Directive Has Finished Rendering the DOM for ShareThis

Within my Angular (1.3) application, I have a list of records being displayed using ng-repeat. The template includes a directive that contains ShareThis controls from ShareThis, which are activated once the DOM is loaded. Upon the initial load of the app, ...

PHALCON array entry now in place

Currently, I am facing an issue while trying to insert multiple data from an array. It seems that only the last piece of data is being inserted each time. Below is the front-end code snippet responsible for sending the data: let payload = new FormData(); ...

Error encountered while rendering a functional component in ReactJS

Recently, I've been utilizing functional components in my project, like this: const Component = (props) => <div>asdasdasd</div>. However, I'm encountering a cryptic error when trying to render my application. The console displays a ...

To Default or Not to Default: Dynamic Imports in React Router 3 for Webpack Code-Splitting

Lately, I've been focusing on upgrading my project from webpack 3 (v. 3.3.0) to webpack 4 (v. 4.44.2). Building and compiling went smoothly, but for some reason, nothing was being rendered on the screen. Upon comparing the parameters passed to Router ...

How to store data in MongoDB without relying on specific request bodies

I realize that I can simplify the code: var event = new EventModel(req.body); event.save....... If the input names match the attribute names in my database, mongoose can save by simply passing req.body. However, there is an issue with handling dateO sep ...

Obtain information about a div element while scrolling

Looking to enhance my social feed page by adding a view count feature for each post. The challenge is figuring out how to keep track of views as the user scrolls down the page. Any suggestions? ...

The remove() method in AJAX function is not functioning as expected

Within a jQuery click event that uses $.post(), I have a .remove() function inside the response callback. Strangely, the alert() seems to function correctly when the code is executed, but the .remove() does not work at all, even though the alert() in the ...

React and the Use of External Libraries

Currently, I am developing a website with react and I am in need of installing mojs, mojs-timeline, and mojs-curve-editor. Unfortunately, these are not available as npm packages. Can anyone suggest the most effective method to integrate them into my react ...

My AJAX function is not functioning as intended

I'm currently developing a time management system for my workplace. As I was coding, I implemented a feature that allows users to configure the database details similar to the setup process in WordPress. Once the data is saved successfully, I aim to d ...

Transferring data between Jade templates

In the process of building a compact CMS system prior to diving into Node.js websites using Express, Jade, and Bootstrap, I encountered a minor setback. To enhance modularity, I am employing includes for various components like the navigation header on th ...

Using `require` in place of `script` tags in a three.js file when working with Node.js environment

Instead of using the html script tag, I have implemented javascript require in my three.js file for node.js. Here is a snippet from an html file: <script src="../build/three.js"></script> <script src="js/controls/DragControls.js"></s ...

Using Axios with Mongoose to Update Documents in Not Working State

I'm currently working on implementing an edit feature for updating posts. My goal is to initially update a specific post by its ID and then make it more dynamic. Although I am able to successfully send a PUT request using axios, I'm not getting ...

ECharts - Version 3.1.6 Event Plugin

I am looking for advice regarding the management of two charts with reference to echars from Baidu (version 3.1.6). Is there a way to control both charts by engaging in a click event on one of them? In simpler terms, how can I capture and respond to the c ...

Converting JSON array to custom object array in TypeScript

As a newcomer to this area, please excuse any inaccuracies in my language. Don't hesitate to ask for more details if needed. I currently have some TypeScript interfaces: export interface Item { id: string type: string state: string } ex ...

The function will still be executed even if the assigned ID is not found within the document

I was working with the following javascript code: $(document).ready(function () { ... $("#mySelector").ready(function () { window.alert('What the heck!!!'); }); }); I expected a pop-up window to appear every time the mySel ...

Unlock the full potential of Laravel and Vue.js with these advanced techniques

I am currently working with vue.js 2.0 and Laravel 5.4. I am interested in finding a more efficient way to pass data from Controllers to views without losing the value or being overwritten by the v-model. When using Vue.js, the value in data is defined li ...

Alert: A notification when navigating away from your site

Is there a way to notify users when they click on an external link that they are leaving your site? <div class="row"> <div class="col-lg-12"> <div class="form-group"> *If you need information on other applicable forms, you ...

Extracting information from a designated website using Python, including pages with search functionality and javascript features

Visit the website where you will find a search input box in html. Input a company name into the search box, select the first suggestion from the drop-down menu (like "Anglo American plc"), navigate to the URL containing information about that specific com ...

Adjust the color of a DIV based on the text value retrieved from an external source

I am looking to dynamically change the text color between red and green based on a numeric value received from an external source (API). If the value is greater than or equal to 50, it should be displayed in red. If it's less than 50, then it should ...