How can I develop Vue CLI locally with "/" as the root path, but deploy it with "/subfolder/" as the root path?

I currently have a Vue application set up locally, where the main /index.html serves as the webroot. However, when I deploy the application, I would like the subfolder /stats to be considered the root (and ensure that all my routes still function correctly).

Is there a way to achieve this without having to manually modify my router/index.js?

vue.config.js

// I have tried the following configuration, but it doesn't seem to work
module.exports = {
  publicPath: process.env.NODE_ENV === "production" ? "/stats/" : "/",
};

router.js

const routes = [
  {
    path: "/",
    name: "HomeView",
    component: HomeView,
  },
  {
    path: "/grid",
    name: "GridView",
    component: GridView,
  },
  ...
]

Answer №1

One important tip is to ensure that you configure the router's base property to correspond with your specified publicPath

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL, // 👈 specify the "base" property in this location
  routes
})

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

The nested mapping operation produces no output

I am currently working on a React.js Dashboard project using MUI. In this project, I have a list of courses and athletes. Each athlete can be enrolled in multiple courses. For each enrolled course, I want to display a Card showing the course name and venu ...

Tips for effortlessly enlarging an element

When you click on "#sidebarnav>li", the following happens: 1) The second child of it - <ul> element will expand and its class toggles between "collapse" and "collapse in". 2) "#sidebarnav>li" will receive the "active" class. 3) The "aria-ex ...

What could be causing the useState function to not update the value?

I am experimenting with React.js but unfortunately, my desired functionality is not working as expected. Here is the code snippet I am currently working with: import React, { useState } from 'react'; function App() { const [count, setCount ...

What is the best way to transfer my current_user.id to an AngularJS Controller?

Currently, I am retrieving my current_user.id from Ruby on Rails and attempting to transfer it to my angular controller using an HTML hidden input. <input type="hidden" ng-model="user_id" value="<%= current_user.id %>"></input> While de ...

Tips for handling ng-if during element presence checks

There's a hidden div on my web page that is controlled by an ng-if directive. I'm looking to create a test that confirms the presence of the element only when it should be visible. If the condition set by ng-if is not met, the element is complete ...

The jQuery Validate Plugin only validates emails when the user moves away from the input field

Resolved: Upon inspecting my version of jquery-validate.js, I discovered that it was missing the onkeyup handler. Despite using version 1.12 Opre, which should have had this functionality according to its Github history from 2013, it seemed like there may ...

Tips for properly sending a JWT token

When working on my angular application, I encountered an issue while trying to send a jwt token as a header for request authorization. The error 500 was triggered due to the jwt token being sent in an incorrect format. Here is how I am currently sending it ...

Efficient method to update the state of a result in React JS using hooks within an asynchronous function and useState

How can I ensure the state is updated correctly after using setState? I found a code example similar to mine at Why react hook value is not updated in async function?, but it doesn't provide a solution to the problem. Any help would be greatly appreci ...

The design template is failing to be implemented on my personal server utilizing node.js

I've encountered an issue while developing the signup page on my local server using Bootstrap 4. The CSS is not getting applied properly when I run it locally, although it displays correctly in the browser. Can someone explain why this is happening? ...

Establishing the NumbroJS cultural settings

I have been attempting to modify numbro's culture. I initially tried the straightforward method, but encountered an error: Unknown culture : ' + code numbro.culture('fr-FR'); My attempt looked like this: const br = require('numb ...

What is the recommended lifecycle hook in Vue.js2 to execute a function when the page is loaded?

I have a dynamic table that can be filled with various numbers of rows, and I want to add an overlay before the data is loaded using my applyOverlay() function. Below is the structure of my HTML: <table id="table" class="datatable" s ...

Changing the selected value in a dropdown menu when the first dropdown is selected

Currently, I am facing an issue where changing the value of the first dropdown also changes the value of the second dropdown. How can I resolve this issue? I want to ensure that when I change the value of the first dropdown, the second dropdown does not i ...

The error message "TypeError: this.Vue.axios is not defined when utilizing the axios HTTP driver"

After implementing vue-auth (vue-auth on GitHub) with the Axios HTTP driver, I encountered a browser console error: TypeError: this.Vue.axios is undefined main.js import Vue from "vue"; import App from "./App.vue"; import axios from "axios"; import "./l ...

Leveraging the parent component class to apply styles to various elements in Vue

How can I transfer a class prop from a parent component to a different element within the Vue component structure? My project is using Vue 3. // Parent Component <ParentCompy title="hello" class="someClassName"> ... // ...

"Enhance Your Website with qTip2 Feature to Load Multiple AJAX Sites Simult

I'm currently utilizing the qTip2 library for my project and I've implemented their AJAX retrieval functions following this example: http://jsfiddle.net/L6yq3/1861/. To enhance my query, I have modified their HTML to include multiple links. The ...

What is the method for inserting a point into an obj file using three.js?

Is there a way to incorporate a sphere marker into an obj file using three.js's onClick function? I aim for the marker to move along with the obj file's rotation, and also be able to retrieve and store information about its placement. Can three.j ...

A guide to examining pixels in Three.js

I have a query about comparing two textures at a pixel level in three.js. I am unsure of how to achieve this as the documentation for Three.js does not provide clear answers, with some classes remaining undocumented. In summary, I am looking to determine ...

Having trouble changing the chosen selection in the material UI dropdown menu

I've encountered an issue with my material ui code for a select dropdown. It seems that the selected option is not updating properly within the dropdown. <FormControl variant="outlined" className={classes.formControl}> <InputLabel ref={ ...

Is there a way to determine the desired width of an element using jQuery prior to rendering it?

I am currently facing an issue with an element that has not yet been added to the body. Despite having all the necessary classes for a specific box model, I am unable to determine its width before it is appended. When inspecting the element using Firebug, ...

Error message: "Module not found" encountered while executing test case

I am a beginner in node and nightwatch and I have followed all the initial instructions from setting up node, npm, selenium standalone, starting the selenium driver. I also downloaded the chrome driver and placed it in the same directory. I created the con ...