When a 404 page is set with an alias * in Vue router, the welcome page is not redirected to

I've encountered an issue with my route configuration. I expected the router to redirect the client to /dashboard when entering the page without any url extension, but it's displaying the 404 page instead. Interestingly, commenting out alias: '*' for the 404 page seemed to enable the redirect as intended.

function configRoutes() {
    return [
        // Route configuration code goes here...
    ]
}

Any suggestions on how to resolve this problem?

Answer №1

To optimize your routing setup, consider moving the 404 page higher in the hierarchy to ensure it is not nested within any children arrays. Instead of assigning an alias to the page, set its path to *. Remember that the catch-all route should always be positioned last in the array to prevent it from obscuring other routes listed below.


Scenario 1 - TheContainer wraps all routes

App.vue

<template>
  <TheContainer>
    <MySidebar slot="sidebar" />
    <router-view />
  </TheContainer>
</template>

Scenario 2 - Unique layout for each route

App.vue

<template>
  <router-view />
</template>

Route A

<template>
  <LayoutA>
    <Sidebar slot="side" />
    <Toolbar slot="top" />
    <!-- custom content for this route -->
  </LayoutA>
</template>

Route B

<template>
  <LayoutY>
    <MyToolbar slot="top" />
    <!-- specific content for this route -->
    <MyFooter slot="bottom" />
  </LayoutY>
</template>

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

Troubleshooting auth error with Android and nativescript-plugin-firebase

I am currently utilizing this plugin in my application: https://github.com/EddyVerbruggen/nativescript-plugin-firebase Unfortunately, when using my real device on a 3G network, I encounter the following error: auth/network-request-failed Thrown if a netw ...

Undefined is the value assigned to Javascript Dot Notation

When using dot notation to access objects with a '.', I am encountering an issue that I cannot seem to figure out. The success function in my jQuery $.ajax function looks like this: success: function(data){ console.log('data = ' + da ...

Translating JavaScript code into C++

Check out this JS code below: var Info = { result1: { ID1: "some text", ID2: "some text", }, result2: { ID1: "some text", ID2: "some text", } } I am looking to convert the above code to C++. One approach I a ...

Implementing dynamic webpage updates based on dropdown list selections

In my webpage, I am displaying a list of movies fetched from an API. The issue I am facing is related to sorting the movies based on user selection. When I uncomment one of the sort methods in my code, it works as intended. What I want to achieve is that ...

JavaScript vs. markup: deciding between generating an extensive list of options or including them directly in

Recently, I encountered an issue with a .NET page that included a large number of identical dropdown lists within a repeater. Unfortunately, the rendering performance of the website was below expectations. In an attempt to improve the performance, I exper ...

What is the mechanism behind AJAX functioning without the need to refresh the page?

I came across a code (not written by me) for a button that allows users to bookmark a person and add them to a shortlist. Here's how the code looks: Here is the JS & Ajax portion: self.isMarked = ko.observable(@(Model.Application.IsMarked ? "tru ...

Tips for interpreting JSON information and showcasing it with the assistance of Ajax in JQuery?

There's a request made to the system via AJAX that returns JSON as a response, which is then displayed in an HTML table. The HTML code for displaying the data looks like this: <table id="documentDisplay"> <thead> <tr ...

Bower downloads the identical package but arranges it in a distinct file structure

We operate a TeamCity build server that is utilizing three different buildusers all configured similarly. We have integrated an angular/grunt project using yeoman Update 6 Noted an issue with bower https://github.com/bower/bower/issues/1709 Why does bow ...

Is it possible to retrieve a file from a POST request in Express and save it

I am attempting to initiate a file download upon receiving a POST request on my server. This is my attempted code: router.post('/generate', function (req, res) { console.log('THIS IS RUNNING'); var file = __dirname + '/blah.tx ...

"Implementing an infinite scroll feature using AJAX and PHP to dynamically load

Currently, I am in the process of loading a significant number of products on a single page and have decided to use an OnScroll loading approach. The following is the method that I am implementing: <ul id="productContainer"> </ul> JQuery: $ ...

Can you modify a attribute value in one HTML file from another?

I currently have a website and I am looking to modify the aria-expanded value of an expandable paragraph on another page when I click on an anchor element in the main page. What changes do I need to make in my main.html file in order to update the aria-exp ...

Populate an HTML table with JSON data retrieved from an API endpoint

I am currently attempting to present JSON data in a tabular format on a website. The raw data retrieved from the API endpoint appears as follows: {"body":"[{\"id\":\"67341472528\",\"name&bso ...

Linking Vue data to various divs or tables for mounting

Just starting out with vue Attempting to design a basic table or multiple divs (5 rows by 5 columns) I want to bind data to each of those td\div elements If necessary, I'm open to changing the data format that's coming in, but my vision i ...

Update object properties in Angular controller dynamically

Take a look at my simple plunker Within the code, I am attempting to link a scope variable to an object property. $scope.name = 'World'; var obj = { "name":$scope.name } $scope.$watch('name', function(){ console.log(obj["name"]); ...

Accessing objects from a loop in JavaScript

In an effort to adhere to the principle of avoiding "polluting the global namespace" and due to the consensus that global variables are typically discouraged, I made a modification in my code by replacing global variables: stBgAsset15_src = $image.at ...

Specify the CSS bundle during the compilation of a Vue application

I am faced with the challenge of using a single code-base for my Vue application, but needing to compile it with different styles depending on the end user. Each end user (which in this case refers to a group or organization) has their own specific CSS fil ...

It seems that although both axios.put methods are identical, only one is functioning properly

Could someone clarify the distinction between these two syntaxes and why the first one is not functioning correctly? Attempting to use the first code block results in a 401 error: const handleSubmit = () => { axios.put(`url`, { headers: { Aut ...

Error encountered when attempting to insert data into a PostgreSQL database using Node.js and Sequelize

I'm currently using the node sequelize library to handle data insertion in a postgress database. Below is the user model defined in the Users.ts file: export class User extends Sequelize.Model { public id!: number; public name: string; public ...

Customizing settings for reinitializing the Ajax range slider in Foundation 5

Is there a way to initialize foundation.slider.js and update settings through ajax? For instance, if I have a range slider with a step limit of 5, can I dynamically change it to 7 after receiving an ajax response by clicking a button? ...

Compare and contrast the functions of scrollToIndex and manual scrolling in a React Native FlatList

Currently, my FlatList is set up to automatically scroll item by item based on a time series using the scrollToIndex function. However, I also want to allow users to manually scroll through the list and temporarily pause the automatic scrolling when this ...