Tips for setting up NuxtJS build for personalized file paths without needing to adjust router settings

I recently created a single-page application (ssr: false) using NuxtJS. However, after building the project, I noticed that the file paths for the javascript and CSS files are relative to the domain's root folder instead of the dist folder. For example,

<script src="/_nuxt/e247009.js"></script>
. This caused a browser error:

"The resource from "the url" was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff)."

The paths within my css fonts-face also experienced this issue.

To resolve the error, I followed a solution provided here: , by adjusting the router option like this:

router: {
  base: './'
}

However, now a new problem has emerged - when loading index.html located in the project's root, the nuxt router displays an error:

This page could not be found

Is there a way to customize file paths without altering the router options to prevent breaking the router?

Answer №1

While OP initially ran the project using Webstorm IDE and assumed that setting target: 'static' would enable it to function in the local environment, it is important to note that modern development is more complex than this.

Therefore, it is necessary to utilize the webpack-dev-server local server to take advantage of all the advanced features of modern development such as HMR, file-hashing, and SASS integration.

Executing yarn dev (or npm run dev) will ensure that the project runs smoothly, benefiting from a pre-configured Webpack v4 setup provided by the Nuxt core team.

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 steps should I take to resolve the textarea border bottom CSS effect?

My simple border bottom animation is working fine with a basic input element, but it's not functioning properly when used with a textarea. (If using JavaScript is necessary for a solution, please provide guidance) How can I adjust the height of a te ...

My AngularJS ng-show functionality is not functioning as expected. I have already reviewed the syntax and still encountering issues

Having trouble with my ng-show, it's not functioning as expected <div class="form-group"> <label class="control-label col-sm-4">NotesTest:</label> <div class="col-sm-4"> <textarea class="form-control ...

How to capture and log request and response data when using the HttpService in NestJS?

Is there a way to log requests, responses, and errors using the HttpService within the HttpModule? In the past, I have used Interceptors with AXIOS. While HttpService wraps axios, I'm having trouble adding interceptors. There doesn't seem to be ...

Tips for creating a navigation bar item that displays a component depending on its active state

Trying to enhance the modularity of my code but facing difficulties. I have a tab bar and I want to render a specific component based on the clicked nav/tab item. Struggling with passing props properly, as the current code only recognizes the children valu ...

How to display an array with JSON objects in Angular 4

Looking to display specific data from an array in my .html file that originates from my .ts file: myArray: ["03/05/2018", "2:54", "xoxo", "briefing", "your", [{ "Id": "1", "Time": "20:54", "Topic": "mmmmm", "GUEST1": { "Role": "HS" ...

What is the process for displaying HTML page code received from an AJAX response?

My current project involves implementing JavaScript authentication, and I have a specific requirement where I need to open an HTML file once the user successfully logs in. The process involves sending an AJAX request with the user's username and passw ...

customize Form Modal Bootstrap with AJAX Chained Dropdown for pre-selected options

I am facing an issue with a chained dropdown on a bootstrap modal, Here is the code snippet: function changeDetail(id) { var id = id; $('#edit').prop('hidden', true); $('#modal_form').prop('hidden', fa ...

Adjusting the size of icons to fit within a container

I need a div that can display up to 7 icons, depending on certain selections. These icons are from ionicons library. Here is the current code snippet: <div class="item item-text-wrap" style="text-align:center;"> <button class="button" style=" ...

Exploring ways to improve the organization of homework code using arrays and loops after it has already been graded, aiming to enhance and refine it

I'm trying to optimize my code which currently consists of 10 variables and 10 functions. Each function is responsible for retrieving a specific variable and displaying it on an HTML page when a button is clicked. I want to use JavaScript to store the ...

Executing system commands using Groovy is a breeze

One of the scripts I have is a sample.js script that allows me to view files located on the server myHost. It works perfectly: var exec = require('ssh-exec') var v_host = 'myHost' exec('ls -lh', { user: 'username&apo ...

XPathSelectorError: The provided xpath expression is invalid and unable to locate the specified element

Here is an HTML snippet element: <a ng-click="nodes.setViewType('tiles',true)"> <span class="fa fa-check Tick-Inactive" ng-class="nodes.viewType == 'tiles'? 'Tick-Active':'Tick-Inactive'" style="">< ...

"Vue: The persistent issue of props returning as undefined continues to trouble developers

While checking my Root and child component (Topbar), I keep finding that the foo prop is undefined in each one. It's perplexing because I have defined it properly. app.js window.Vue = require('vue'); Vue.component('Topbar', ...

Click event triggered the function, however it was unable to modify the variable in $scope

<!doctype html> <html ng-app> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script> <script src="script.js"></script> </head> <body> <ul c ...

Ways to retrieve specific text from an HTML dropdown with a changing ID

I need assistance with extracting values from a JSON string within my webpage. I have implemented dynamic IDs in my select drop-down and now aim to create an IF loop that compares the selected value in the drop down to "some text." If the comparison matche ...

The v-model for two-way binding seems to be malfunctioning, with a browser error or warning stating that the use of withDirectives is restricted to render functions

Currently utilizing VITE v5.0.8. This file is dex.html <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content=&q ...

Utilizing various Material UI Sliders on a single page with shared color properties

After creating a component called "SliderBox", I noticed that it returns a div containing a Material UI Slider with createMuiTheme and an input component. The "SliderBox" component utilizes an onHover method on the parent div to change the component' ...

Dynamic Column Placement in Tabulator with AutoColumns and AJAX Integration

Hey there, I'm currently working on incorporating the autoColumns feature in Tabulator using data retrieved via AJAX. My aim is to dynamically add column definition information based on each column's requirements, like filters, sorting, etc. Desp ...

When you click on the image link, watch as the page gracefully transitions to a new one determined by the URL

I need assistance with a functionality where an image inside a div has a link to the next page. When this image is clicked, it should smoothly transition to the new page specified by its link. Any help with implementing this would be greatly appreciated. ...

How can we eliminate every item of a specific type from an array?

On my Angular controller, I've set up a method linked to a click handler in the scope. This function checks if a checkbox is checked or unchecked and toggles the associated objects in an array accordingly. The code block where I push objects back int ...

Validating data for Telegram Web Bots using JavaScript

Struggling with creating a user verification script for my Telegram web app bots. Need help troubleshooting. import sha256 from 'js-sha256' const telegram = window.Telegram.WebApp const bot_token = '<bot-token>' const data_check_ ...