Progress tracking for async route guards in Vue router

Using async tasks in my router's navigation guard:

router.beforeEach((to, from, next) => {
  somethingAsync().done(next)
})

I am wondering if the router provides any indication for when it is currently "loading," or if I need to manage this myself. Currently, the content appears in

<router-view></router-view>
once the async task is finished. My current approach involves tracking active tasks in my Vuex store and displaying a loading element alongside the router view.

Answer №1

In order to achieve the desired outcome, here's my approach:

  • Utilize Axios or another tool with interceptors https://example.com/axios
  • Create a component that maintains a count of pending requests. Display a loading element when this count is greater than zero.
  • Configure the interceptors to increment the counter upon request and decrement it upon receiving a response.

If necessary, I can provide some sample code for reference.

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

Protractor - Error: prop is undefined

Need assistance in identifying an error. Currently, I am learning Protractor and attempting to create a basic test using Page Object. //login_pageObject.js let loginContainer = function() { this.usernameInput = $("input.login-form-01"); this.passwordInp ...

Issue encountered when passing an argument to a map callback function within a React component

I am encountering an error in my React component while using a map function to display data. The issue arises when passing a callback function and trying to access the classes property, resulting in the error message Uncaught ReferenceError: classes is no ...

What are the issues with the filterSystem function?

Currently, I have a slider filter feature that aims to filter text based on the attribute data-length. The idea is for the slider to display text with a data-length value equal to or less than the slider's current value. Below is the code for the sli ...

Customize v-text-field label styling using Vuefity translate

Looking to localize the text displayed on v-text-field and vuetify-google-autocomplete components in Vuetify. Here's a snippet of the code: <template>(...) <v-text-field label="$t('common.nameLabel')" v-model="registerName" r ...

pass the table ID to the controller using AngularJS

Curious about how to pass the selected row's id from a table to the controller when displaying its details? Take a look at this code snippet: app.js: .controller("etudmodifCtrl", ["$scope", "$http", "filterFilter", "$rootScope", "logger", "$filter", ...

PHP Generate an array with predefined slots

I have a PHP array that is populated with data from a stored procedure: <root> <dataSet> <reimbursementMonth>6</reimbursementMonth> <reimbursementYear>2014</reimbur ...

The Yeoman Angular Coffee router is not routing properly and displays an error message "cannot GET"

Struggling with getting the router to load a basic template after setting up a Yeoman angular scaffolder installation. Here's my configuration: // index.html <body ng-app="mvmdApp"> <div class="container" ng-view=""></div>// not ...

Accessing Route Parameters from Any Component

If my URL follows this structure: /blog/[post_id]/something What's the best practice for passing $post_id to any component within the tree? I'm familiar with retrieving route parameters using getInitialProps, but I struggle with passing values ...

There was an error encountered with the value used in the weak set at the time of adding it to WeakSet.add

I've been working on creating a test file for a Vue component, but I seem to be struggling with where I'm making mistakes. This is all new to me as I am just getting started with unit testing. Despite spending some time searching online, ...

Is it possible to caution users before refreshing the page, while still allowing them to

I have a script that displays a warning message to the user when they attempt to refresh the page. It works perfectly for that purpose. However, my issue is that this same alert pops up when a user clicks on a button or a link within the website itself. I ...

Is it possible to notify the user directly from the route or middleware?

In my current setup, I am utilizing a route to verify the validity of a token. If the token is invalid, I redirect the user to the login page. I am considering two options for notifying users when they are being logged out: either through an alert message ...

Is the asynchronous nature of setState truly reliable?

As I delve into learning React, an interesting topic that keeps popping up is the async nature of setState. It's often mentioned that if you try to console.log(state) immediately after calling setState, it will display the old value instead of the upd ...

What is the best way to capture a form submission when there are no errors?

My form includes a validation check for valid fields upon submission. Here is an example of how it is structured: <form class="form-horizontal" method="post" action="#" name="basic_validate" id="basic_validate" /> <div class="con ...

Concealing a section of a table with JavaScript while preserving the original table structure

I made some adjustments to the script tag: $(document).ready(function) { Now, the evenTd's are hidden correctly. Here is the table with the code provided: <table> <tr> <td>itemOne</td> <td class="even ...

Adjusting the width of a nested Angular custom directive within an *ngIf statement to an absolute value

I'm struggling with a custom angular directive that I only want to display conditionally using ng-if. The directive contains HTML elements, one of which is positioned absolutely. My goal is to make the absolute element's width match the root wid ...

What are the best methods to safeguard an audio file and integrate it into my React Native application for playback?

What is the best method to secure my audio file from unauthorized media player apps while ensuring it can still be played on my React Native application? The backend includes Node.js and Express.js. ...

Get the base64 encoding of a File object by utilizing the FileReader.readAsDataURL() method

Currently, I am facing an issue with converting a JS File object into a base64 value and returning that value within a JSON object. My approach involves using FileReader.readAsDataURL(), however, due to the asynchronous nature of this process, it appears t ...

Different ways to rearrange the placement of Export buttons in a personalized div or outside the table using Datatable

I would like to display the export buttons outside of the table. While searching on stackoverflow, I came across an example that uses the Select options method. You can find the example here. If anyone knows how to achieve this, please modify it and shar ...

Checking if the slot has no content or is empty

I recently created a small Loading component with the default text set to 'Loading...'. I thought using slots was a good idea, so here is what my template looks like: <p class="loading"><i class="fa fa-spinner fa-spin"></i>< ...

Obtain real-time Notification API integration within individual components using NuxtJS

I have a question that may seem simple, but I need your assistance. I am working on a Notification component that receives real-time notifications through Axios (refreshing every time), and I'm struggling to implement it. Here is my Notification Comp ...