When refreshing a page in Nuxtjs, the dynamic page fails to load its CSS and JS files

Every time I open a dynamic page in Nuxtjs for the first time, it works perfectly. However, if I reload the page manually, all of the css and js files stop working, causing the page to break. When I open these styling and js files in the browser from their page source, it shows " /* style not found */ ". Can someone provide guidance on why this is happening and what the solution might be? My app's mode is set to universal.

In my nuxt.config.js file, the script tag refers to files located in the static/assets folder:

https://i.sstatic.net/R06Ao.jpg

This image illustrates my issue:

https://i.sstatic.net/hECts.jpg

The problem arises because the path for the pages/project/id page is one directory up from the static folder files, while the direct path for pages/ViewProject file remains different. I am unsure how to make the paths consistent for both nested and direct pages. Could anyone offer assistance with this?

Answer №1

After tirelessly scouring the internet for answers, I have finally stumbled upon a solution. I am sharing it here in hopes that it will assist others and save them valuable time. To prevent Nuxt from altering script paths by adding prefixes, I added the script source to the head object in my nuxt.config.js like so:

import { join } from 'path'
export default {
  head: {
         script: [
          {
            src: join('/', `assets/plugins/global/plugins.bundle.js`),
            body: true
          }
    ]
}

Now, whether it be from nested pages or direct pages within the pages directory, scripts are loading correctly.

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

Vue.js computed property experiencing a minor setback

I'm currently working on developing a test-taking system using Vue and Laravel. When a user inputs the test code and email address, they are directed to the test page. To display all the test questions based on the entered code, I implemented a naviga ...

Can a universal attach() handler be implemented for all viewmodels worldwide?

In my Aurelia use case, I am looking to implement a handler that will run for every attached view. Specifically, I need an HTML5 polyfill for date and number inputs using querySelector. While I could manually call this in each view, I am curious if there i ...

Executing a Function Prior to onClick Event of a Link Element in Next.js

While working on a slider/carousel, I encountered an issue. Each photo in the slider should be draggable back and forth, with a click taking the user to a product page. I am using next.js with react-flickity-component for this purpose. Please note that thi ...

Angular - a simple method to determine the number of non-empty inputs in a complex template-driven form

As I work on multiple substantial Angular 11 template forms containing basic inputs like text, radiolists, and checkboxes, I am looking for the most effective method to calculate the percentage of completed inputs while the user is actively engaging with ...

Is it possible to integrate the Firestore npm library into my Express application?

Recently, I created my own library to act as a nosql database on my node.js web server in place of mongodb. I came across this interesting quote: Applications that use Google's Server SDKs should not be used in end-user environments, such as on pho ...

Error: html2canvas encountered an uncaught undefined promise

Currently, I am working with an HTML canvas tag: <canvas id="myCanvas"></canvas> I have successfully created a drawing on this canvas, and it looks exactly how I wanted it to. However, when trying to convert it to a PNG file using html2canvas ...

Spring load without CSS

Upon successful login, I am redirected to my main site using the following controller: //Login Success @GetMapping("/login-success") public ModelAndView loginSuccess() { return new ModelAndView("/cont/home.html"); } The URL for this redirection i ...

What is preventing me from being able to manipulate the data retrieved from this ajax request?

I've been attempting to make an ajax call to my json server on localhost:3000 in order to retrieve an object that I can manipulate and display on a webpage. However, no matter what I try, I just can't seem to console log the (data) so that I can ...

The AJAX functionality does not seem to be activated when scrolling

Utilizing AJAX for continuous scrolling. Content loads initially but fails to load with scroll. What could be the issue? jQuery: function loadContent() { $.ajax({ url: 'loadmore.php', dataType: 'html', suc ...

What is the correct way to establish and terminate a MongoDB connection in a Node.js application?

Hey everyone, I have a piece of code at this link (https://github.com/MrRav3n/Angular-Marketplace/blob/master/server.js) and I'm curious if I am properly starting and ending my database connection. Should I connect and end the db connection in every a ...

Are there any web browsers that automatically switch to a non-SSL connection if an attempt to connect with SSL

I regularly utilize jQuery along with jQuery.ajax to make connections between pages. I am interested in establishing a connection from a non-SSL page to an SSL page using ajax. Are there any web browsers that will attempt to connect via non-SSL if the con ...

Issues arise when attempting to run JQuery functions with the $ symbol in the head tag of HTML

Because of the limitations imposed by Squarespace, I am only able to include code via the Head tag. When the script reaches the $ part of JQuery, it seems to not execute at all. After testing with numerous console.log() statements, I observed that the webp ...

Is your div not loading correctly due to JQuery or Javascript?

PHP Version 7.0 JQuery Version 3.1.0 It is noticeable that the content above gets copied and pasted every five seconds instead of refreshing. The aim is to refresh the include every five seconds. Website: Code: <!doctype html> <html><h ...

Can a FilePicker be Cleared Automatically through Code?

Currently, I am implementing an‘<input type="file" . . .’ to select files individually and then attach them to a table located right under the file picker. This functionality is quite similar to using the attachment button on a SharePoint form’s r ...

Troubles with showcasing icons on a website

I need some help with a minor issue that I'm stuck on. I'm trying to display an information icon that, when clicked, opens a pdf. The strange thing is that the icon doesn't show up on the page even though it exists on the server. However, wh ...

Challenge encountered in posting a variable generated through ajax

Embarking on my first attempt at utilizing ajax has been quite challenging. Essentially, when an option is selected from the initial field, javascript and xml trigger a php script that generates the next dropdown menu based on information fetched from an S ...

Guidelines for utilizing React to select parameters in an Axios request

As a newcomer to ReactJs, I am working with a Product table on MySQL. I have successfully developed a dynamic table in the front-end using ReactJS along with MySQL and NodeJs on the backend. The dynamic table consists of four columns: Product, Quantity, Pr ...

JavaScript Leaflet Map fails to load

I am trying to incorporate multiple maps on my page, including both 2Gis and Leaflet. The 2Gis map is functioning properly, as it is based on the Leaflet library. However, I am encountering an issue with Leaflet when it is used in conjunction with 2Gis. Th ...

After adding on, do you wish to eliminate?

I have implemented zoom buttons on my Map container However, I need to hide these zoom buttons when a specific map image is displayed Code: JS: Map = function() { //private: var $MapContainer; this.initMap = function($container, zoomHidden) { $Map ...

The localhost successfully accessed req.session.userid, but unfortunately the virtual host cannot be reached at this time

Having some trouble here... I've spent days trying to figure it out but nothing seems to be working. I am using Node.js Express session on the backend with users. When I log in, I set req.session.userId = "userid" and have a middleware that ...