Tips for maintaining the current route in Vue.js after a page refresh while running the Vue.js project in development mode on a specific port?

In my router.ts file, I have defined two routes:

export default new Router({
    mode: "history",
    routes: [
        { path: "/", component: require("./components/dashboard/Dashboard.vue")},
        { path: "/counter", component: require("./components/counter/Counter.vue") }
    ],
});

Vue.use((Router) as any);

When I directly visit http://localhost:5000/counter in the browser, it redirects me to the "/" route instead of the "/counter" route. The same issue occurs when I reload the page. However, if I navigate to /counter using:

<router-link to="/counter">Counter</router-link>

and then reload the page, the counter page does not show up anymore and defaults back to the home route. This is happening on localhost without the involvement of Nginx or similar services, as explained here: https://router.vuejs.org/en/essentials/history-mode.html

Answer №1

Even though it is not ideal, the exact property in vue-router might be able to assist you, give this a shot:

<router-link to="/dashboard" exact>Dashboard</router-link>

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

Cookie set upon clicking a particular element exclusively

Looking to toggle a class when clicking an element and preserve it post page load using jQuery or JavaScript. Here's what I currently have, successfully adding the class upon click but not retaining it after reload: jQuery("a.action.towishlist").clic ...

Tips for creating a stylish ReactJs Header component that stays fixed at the top of the page

Having an issue with my Header component - I want it to remain fixed at the top while scrolling down. Here's the current code: I've attempted using "position = fixed", but it caused my header to resize. Then, I tried setting its width to "width ...

Is there a specific method for organizing cached buffer conversions in Node.js for optimal efficiency?

In a GitHub discussion, it was pointed out that the Map's .has method does not work with buffers because identical buffers are considered as distinct objects. This limitation became apparent when attempting to store buffer string conversions in a map ...

Utilizing the powerful combination of AngularJS and Node.js functions

I am facing an issue with the key_client variable as it needs to be loaded with an md5 value obtained from a module called nodejs get-mac. Despite my efforts, I have been unable to make it work successfully. The problem seems to be that key_client is alw ...

Step-by-step guide on installing both Angular and Nodejs within a single folder

I'm diving into the world of NodeJs and Angular, and I recently created a simple NodeJS application following instructions from this link. However, I encountered an issue when trying to install Angular alongside NodeJS. After running ng new angular-cr ...

Discovering the exact latitude and longitude coordinates along a specific route using Google Maps

I've encountered a problem with finding the latitude and longitude along a given route using Google Maps DirectionsService. I have a JSON dataset containing latitude, longitude, and price details. My goal is to plot markers on the map and determine wh ...

The process of building a Vue application encountered an error when attempting to run the command "npm run build"

I recently cloned a Vue application from GitHub (https://github.com/jimmerioles/progressive-weather-app) for setting up automated deployment in Jenkins. Before proceeding, I'm testing it on my Ubuntu machine (GCP VM). I have already installed Java, No ...

Using Google-Prettify with AngularJS

I have been attempting to implement Google Prettify in my AngularJS project. It seems to be functioning correctly on the main page, but once I navigate to another route using Angular (after ng-view), it stops working properly. You can check out the plunker ...

What is the best method for importing several components from a directory in ReactJS?

I'm looking for a way to import multiple React components from a directory without having to export them separately in an index.js file. Here's the structure of my directory: src/ components/ comp1.js comp2.js comp3.js ...

What is the method for setting a default image to be preloaded in filepond?

Currently, I am working on a Laravel view for editing a record which includes an associated image. My goal is to have the image preloaded inside the input file so that when you submit the form, the same image is sent or you can choose to change it. // Con ...

Deciding between Bull queue and Database Triggers

My current project requires creating records in the database for users on a recurring basis, such as every Monday weekly or biweekly. I have identified two potential solutions to achieve this goal. One option is to utilize Database Triggers to generate ...

Unlocking the power of module augmentation in Typescript: Enhancing library models within your app domain

I currently work with two applications that share the same code base for their models. I am interested in developing and sharing a library model using inheritance in TypeScript. For instance, Pet extends Author. In my current Angular application, I need ...

How can I pass command line variables into an npm script?

I am facing an issue where I am attempting to pass a command line option (which is not stored in version control) to my main script index.js. This script performs specific actions based on a designated S3 bucket. Here is the relevant section from my packa ...

Angular 13: A guide on pulling data from an Excel spreadsheet

I have been encountering issues while trying to display data from a CSV file on a web platform using Angular 13. The errors I am facing are related to binding 'ngModel' and type mismatches in the code. errors Error: src/app/app.component.html:24 ...

Will Node applications be affected as newer versions of their dependencies are released, causing them to stop functioning properly?

I'm currently following an online tutorial on web development topics, and the associated code is hosted on GitHub. After downloading it, I noticed that the directory structure looks like this: E:\dev\angular-components-step-1>dir Direct ...

Yelp API call resulting in an 'undefined' response

When attempting to make an API call using the yelp-fusion, I noticed that the logged result is showing as undefined. It seems like this issue might be related to promises or async functions. It's important for me to maintain this within a function sin ...

Attempting to retrieve assets from an incorrect directory in a rush

Within my express project, I have encountered an issue when rendering the product route with a specific id. It seems that the assets are attempting to load from /products in the public folder (even though this directory does not exist). However, when I ren ...

Having difficulties integrating a login solution due to an error saying "eslint Promise executor functions should not be async no-async-promise-executor"

I'm currently working on integrating a login solution into my Vue app using the JWT Authentication plugin. While I have a test solution that is functional, I'm facing an issue in my main branch where the eslint version seems to be causing an err ...

Angular Bootstrap Modal provides a sleek overlay for user input forms

Trying to access an angular form within scope for validation purposes. Initial Scenario Consider the following HTML: <body ng-controller='MyAwesomeController'> <form name="fooForm"> <textarea ng-model="reason" required= ...

A cutting-edge combination of Laravel version 6.4.1, webpack, Vue.js, and SCSS for dynamic

I have Laravel 6.4.1 installed with some minor tweaks to the default webpack configuration. I am utilizing Vue components along with scoped styling in my project. Upon running npm run dev, everything functions as expected. My Vue component loads and displ ...