Solving the "page not found" issue in NuxtJS: A guide to fixing errors during programmatic redirects

I am currently in the process of converting a Vue project into Nuxt.

I have successfully implemented a navigation guard in the app using router.beforeEach().

Upon accessing the base URL localhost:3000, I encounter the image below:

https://i.sstatic.net/CuoVE.png and here is the corresponding code block that manages that path:

if (to.path == '/') {
      switch (auth.getRole()) {
        case '1':
          next({
            path: '/route_1'
          })
          break
        case '2':
          next({
            path: '/route_2'
          })
          break
        default:
          next({
            path: '/route_3'
          })
          break
      }
    }

However, when I directly enter the address localhost:3000/login in the URL bar, the page renders properly.

EDIT:

Here is my pages folder structure:

https://i.sstatic.net/5D8Yu.png

Any assistance would be greatly appreciated. Thank you!

Answer №1

1- run nuxt build

2- start the project using nuxt start

To get your project up and running, make sure to first build it and then launch it from the dist/ folder.

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

Chosen option from the Bootstrap drop-down menu

Struggling with two problematic input fields on my Bootstrap website... The first is a Bootstrap Typeahead input field: <input type="text" id="typeahead" name='name' placeholder='The name' class="form-control" data-provide="typeahe ...

"When attempting to render a Node inside the render() method in React, the error message 'Objects are not valid as a React child' is

On my webpage, I have managed to display the following: export class OverworldComponent extends React.Component<OverworldComponentProps, {}> { render() { return <b>Hello, world!</b> } } However, instead of showing Hello, ...

Exploring the world of typescript with the power of ts-check

I'm having trouble figuring out how to work with a generic function using TypeScript's new ts-check feature. /** * @type {Reducer<IPoiState, any>} */ const poi = handleActions({ [ADD_BOOKMARK_START]: (state) => { return { ...sta ...

Unveiling an HTML file using the express.static middleware on Replit

When using Replit to render an HTML file with res.sendFile within an app.get function, everything works smoothly. I can include logos, styles, and JavaScript logic files by utilizing the express.static middleware. However, if I attempt to also make the HTM ...

Using an image as an onclick trigger for a JavaScript function

I am working on a registration page as part of my university project where users can create an account and store their information in a MySQL database. One feature I'm implementing is the ability for users to select an avatar picture. Below is the co ...

Revise the JSON format to be compatible with a JavaScript template library

My goal is to utilize JSON data for parsing a template using JavaScript. The Mustache library provides a solution as shown below: var output = $("#output"); // template stored in JS var as a string var templateString = '<div>'+ '< ...

The error message "Attempting to send a message using an undefined 'send' property in the welcomeChannel" is displayed

bot.on('guildMemberAdd', (member) => { console.log(member) const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome'); //const channelId = '789052445485563935' // welcome c ...

Tips for formatting HTML-escaped content in Vue 2 and Vue 3

Currently, I am utilizing user-generated data in a Vue application and the default behavior of html-escaping the data works perfectly. However, I now wish to enable users to search through this data and highlight the matching text in the search results. Th ...

Tips for executing a loop while waiting for a jQuery ajax request to complete

I currently have this code setup: for (var i = 0; i < $total_files; i++) { $.ajax({ type: 'POST', url: 'uploading.php', context: $(this), dataType: 'json', cache: false, contentType: false, pr ...

Seamless mathematical computations while navigating through Javascript

I have created a basic JavaScript calculator that works efficiently. However, after obtaining the result by pressing the "=" button, I would like the returned result to be saved for future use. The "=" button should be capable of being clicked again to ret ...

Controlling the Vuetify Navigation drawer from a separate component

Within my App.vue component, I have a Navigation Drawer menu containing main items and some subitems. These subitems are meant to be displayed only after a specific event, such as a button click on the child component's page (when the variable totalRe ...

The fade in/out effect can only be applied to a div element and not its nested children

I have implemented a JavaScript script that toggles the visibility of elements on a webpage, but I am facing an issue where it only displays the div with a specific id and does not show any other nested divs within that particular div. Below is my CSS cod ...

What sets apart using JQuery to run AJAX from using plain XMLHttpRequest for AJAX requests?

Can you explain the advantages and disadvantages of using JQuery versus XMLHttpRequest for running AJAX code? While I understand that JQuery is essentially a JavaScript library, there must be some key differences to consider. Please elaborate on this top ...

How can I change the background image using CSS instead of HTML?

I initially created a non-responsive website for an existing project. Now I need to convert it into a responsive site. I tried changing the logo image to make it responsive, but it's not working as expected. <td colspan="2" style="background-image ...

Can the roundabout be modified to display 5 elements in front instead of the usual 3?

I am currently utilizing the roundabout plugin to create an infinite slider that continuously loops. However, I am facing an issue where I would like to display 5 elements in a row instead of 3. Has anyone attempted this customization before? Here is my p ...

Using whitespace to format a document.write in JavaScript

I'm in the process of creating a dynamic table using JavaScript and a set of objects. I've managed to structure it, but now I require some extra white space between them, almost like tabbing them out. How can I achieve this efficiently with my cu ...

The resume button is failing to activate any functions

I recently encountered an issue with a JS file that is associated with a Wordpress Plugin, specifically a Quiz plugin featuring a timer. I successfully added a Pause and resume button to the quiz, which effectively pauses and resumes the timer. However, I ...

Issue with disabled button in Angular 2 when using Chrome's autocomplete feature

In a basic login form, the login button is initially disabled with the following code: [disabled]="!password || !loginName" When Chrome's autocomplete feature fills in the values for loginName and password, the button remains disabled after the pa ...

Function for JavaScript Form Validation: Iterating through each element

I have a set of form input elements that need to be iterated through in order to validate them based on their name attributes. I utilized jQuery to accomplish this, using the .each method to loop through the elements and apply/remove a class name to those ...

Is the "json_encode" function dropping the '+' character when using "json.parse"?

Seeking Assistance I have a question regarding the functionality of php function json_encode and js JSON.parse. I seem to be encountering an issue where the '+' character is being dropped somewhere in the process, particularly when dealing with ...