Facing a white canvas while launching my application (Vue Router 4 - Vue 3)

I recently ran my first npm run build command to deploy my Vue3 application on a live server for testing.

After uploading the files to my VPS, I encountered an issue where the server only recognizes route paths when navigated through clicks.

Reloading the page or directly entering a URL results in a browser error. I tried implementing the code from into my .htaccess file with Apache on Centos 7/CWP, but the problem persists. The difference now is that instead of throwing an error, it just stays stuck on the index.html page without displaying any content.

I'm struggling to identify what might be causing this issue.

Below is the snippet of code showing how I have implemented Vue Router 4 in my project:

In my main.js file:

import { createRouter, createWebHistory } from "vue-router"
import Page from "./views/Page.vue"
import Content from "./views/Content.vue"
import BaseSection from "./components/BaseSection.vue"

//ROUTER
const router = createRouter({
    history: createWebHistory(),
    routes: [{
            path: "/",
            name: "Home",
            component: Page,
            meta: {
                title: 'Home'
            }
        },
        {
            path: "/docs/1.0/:title",
            component: Content,
            name: "docs"
        }
    ],
    scrollBehavior(to) {
        if (to.hash) {
            return {
                el: to.hash,
                behavior: 'smooth',
            }
        }
    }
});

app.use(router);

If you have any insights or suggestions on how to resolve this issue, please let me know. Your help would be greatly appreciated.

Thank you.

Sincerely, T.

Answer №1

If you're encountering the blank page error, it might be because you are serving the app from a location other than the domain root. To fix this, you need to configure Vue CLI appropriately. Simply adjust the vue.config.js file in the project root (create it if it's not already there):

module.exports = {
  publicPath: process.env.NODE_ENV === 'production'
    ? '/docs/1.0/'  // Enter your path from the root here
    : '/'
}

To learn more about publicPath, check out the documentation here.

Also, ensure that your .htaccess file is located in /docs/1.0/

Answer №2

To resolve the issue, I successfully rectified it by switching to a port different from the default one it usually operates on.

As an illustration, if the default port is set to localhost:8080, consider attempting

npm run serve -- --port 8085

This solution proved to be the most efficient and effective in my experience.

Answer №3

Don't forget to add the parentheses () after calling the function createWebHistory

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

What is the correct way to use setInterval in a React component's constructor?

I'm trying to set an interval when the main component renders. I attempted to do this in the constructor like so: constructor(props) { super(props); this.props.fetchUserInfo(); this.props.fetchProducts(); setInterval(console.log(&a ...

Show jQuery block and make it fade in

I'm attempting to put together a simple tab system where each tab is supposed to appear using a fadeIn effect. In the code below, the .field element is initially hidden with CSS. Although the tabs are displayed correctly, the desired fadeIn effect is ...

Is add1 missing from the DOM? Learn how to include it

Having an issue with Java-Script and an HTML form. The scenario is that there's a main form with an "Add" button, which when clicked should display a second form. Next to the second form is another button labeled "Add1," which ideally should trigger ...

Disabling a button after clicking using jQuery

There are occasions when I can inadvertently trigger the submit button twice, resulting in the ajax being triggered twice as well. Below is my HTML code: <div class="buttons-area"> <input id="step-two" class="btn btn-primary" type="submit" v ...

Harvesting the local image file

Currently, I have implemented a form that allows users to upload images and crop them. The process flow has been established as follows: 1. User uploads the image 2. Server processes the image and sends it back to the browser 3. User crops the image a ...

When trying to revisit or reload a Laravel project, the Vue Router URL cannot be found

Each time I revisit the vue-router URL, a 404 page not found error is displayed. My application is built on Laravel 5.8 and defined in web.php file. I have attempted various solutions but none of them seem to be effective. Route::get('/{capture_a ...

execution won't be halted by return statement within forEach in JavaScript

const checkAttendanceStudent = (attendance, std_id) => { //check if the teacher made attendance for this current session let checkNow = attendance.find((element) => { if (checkDateAttendance(element.date)) { //check if the s ...

Ensuring the Persistence of Column State in Material-UI DataGrid/DataGridPro when Adjusting Visibility Using Column Toolbar

We have integrated MUI DataGrid into our React project. Currently, I am exploring options to save the state of columns after toggling their visibility using the DataGrid toolbar column menu. After each re-render, the column setup returns to its default st ...

Retrieve documents from MongoDB that were created within the last week and return a count of 0 for any days in which no documents were created

I need to extract documents from the last 7 days stored in my Mongo Database. I have successfully retrieved data in the desired format, where specific dates and the number of tickets created on those dates are returned: { "datesUsed": { ...

An unexpected import token was encountered while using ReactJS and Babel

Every time I attempt to launch my application, an error message pops up that says: (function (exports, require, module, __filename, __dirname) { import { Row } from '../grid' SyntaxError: Unexpected token import I've experimented with vari ...

Create a dynamic select2 field based on the value selected in another dropdown menu

Starting with an initial dropdown where a value needs to be selected: <select id="indexID" name="indexID" class="form-control" onChange="updateSector();" style="width:300px;"> <option value='' selected>Choose an Index</option> ...

React component failing to update after receiving response from server for a specific room using socket.io-client with Python backend

I've developed a server backend in Python with Flask-SocketIO that includes a room feature for private conversations. When a user joins a room, the server triggers a function to inform the frontend where to direct messages to a specific user: socketio ...

Unusual issue encountered when launching an express application in node.js

Starting my app is easy with nodemon - just type nodemon However, I encountered an error when trying node app.js I have checked my package.json and it is properly configured with: "scripts": { "start": "node ./bin/www" } ...

Tips for preventing HTTP Status 415 when sending an ajax request to the server

I am struggling with an AJAX call that should be returning a JSON document function fetchData() { $.ajax({ url: '/x', type: 'GET', data: "json", success: function (data) { // code is miss ...

JavaScript can be utilized to alter the style of a cursor

I'm currently developing a browser game and incorporating custom cursors into it. To ensure the custom cursor is displayed throughout the entire page, I've applied it in my CSS (though setting it up for 'body' occasionally reverts back ...

What is the best way to automatically have the first bar in a column highchart be selected when the page loads?

My highchart consists of a simple column. When I click on any bar in the chart, it gets selected. However, I also want the 1st bar to be selected by default. var chart = $('#container').highcharts(); Upon page load, I have obtained this object. ...

Vue and Express will not be able to communicate with each other with the help of NG

I have successfully established a Vue frontend and an Express backend on a DigitalOcean droplet, with NGINX facilitating communication through an API. The frontend is functioning properly; however, when attempting to access an API route, I encounter a "CON ...

Leverage a JavaScript plugin from the node modules directory within your Vue.js project

Is there a way to import Cal-HeatMap (https://www.npmjs.com/package/cal-heatmap) into my project after saving it with npm install? This is the method I attempted: <script> import calHeatmap from 'cal-heatmap' export default { na ...

Setting references to child components with VueRouter in Vue

I've written the following code snippet in my main.js file for my Vue web application: const routes = { name: "Main", path: "/main", redirect: "/main/home", component: MainComponent, children: [ { path: &quo ...

Tips for sending an ID to a path link in React Js

Can anyone assist me in setting up a path for a component like this "/products?id=uniqueId" in my React Js Project? The unique id is retrieved from the database and varies depending on the product chosen. Below is an excerpt of my code: CodeSandbox App.j ...