What is the process for updating parameters before finalizing a route in Vue.js?

I have set up a route with a value parameter:

  routes.push({
    name: 'test',
    path: '/test/:value',
    component: resolve(__dirname, 'src/pages/test.vue'),
  });

Now, I want to modify the route so that it also includes both value and test as parameters:

  routes.push({
    name: 'test',
    path: '/test/:value',
    component: resolve(__dirname, 'src/pages/test.vue'),
    beforeEnter(to, from, next) {
      to.params.test = 'test';

      next({ params: to.params });
    },
  });

This way, I will be able to access these parameters in a vue page:

async fetch({ store, route }) {
  console.log(route.params.value);
  console.log(route.params.test);
},

However, the code for the beforeEnter is not functioning correctly as the new test parameter is not being sent. Any suggestions on how to fix this?

Answer №1

It appears that the next function accepts a params object as an argument

next(to.params)

Although this method works, it is not documented anywhere in the official documentation

Check out the example codepen for a working demonstration

If you are still encountering issues, consider logging the params as shown in the codepen example

Answer №2

Consider adding a path/name to the next step, such as:

  routes.push({
    name: 'example',
    path: '/example/:value',
    component: resolve(__dirname, 'src/pages/example.vue'),
    beforeEnter(to, from, next) {
      next({ name: 'example', params: { example: 'example' });
    },
  });

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

Guide to using the PUT method in Node.js Express to update a record using the primary key

I'm currently struggling with understanding the proper usage of the put statement in node js. Here is the code I have been using: app.put("/cars/:id", (req, res) => { //retrieving a record based on id (uuid) e.g. http://localhost:3000/cars/a5ad957 ...

Enhance the readability of your Angular/Ionic applications with proper hyphenation

In my Ionic 3 app, I am using an ion-grid. Some words do not fit within the columns and are cut off, continuing on the next row without any hyphens added for proper grammar context. See image https://i.stack.imgur.com/3Q9FX.png. This layout appears quite ...

How to manage ajax URLs across multiple pages?

I have my website set up at http://example.com/foo/ within a directory, separate from the main domain. Through the use of .htaccess, I've configured the URLs to appear as http://example.com/foo/about/, http://example.com/foo/polls/, http://example.com ...

Discovering old (potentially neglected) npm dependencies: strategies for locating outdated packages

I am aware of the npm outdated command, which shows out-of-date dependencies only if a new version has been published. However, in certain cases (such as abandoned projects), there may not be a new version released and the package could still be considere ...

Concealing the label for a specific component in Vue/Nuxt JS

I have developed a reusable input component that includes a label. However, I need the label to be hidden in certain instances (without taking up space, similar to using display:none in CSS), while remaining visible in others. Below is the code for my inp ...

Searching for a specific set of rows within an array? Look no further than jQuery and JavaScript

I'm struggling to find the right title for my project, but I'm doing my best to capture its essence. I am in the process of developing a calculator that compares values within multiple arrays. Each data item in my array consists of 34 rows, wit ...

Having trouble with the search function in my array, as it is consistently returning false instead of the expected result

Aim: I am working on creating a basic search bar that allows users to input a zip code and matches it with zip codes stored in an array. The objective is to develop a function that can determine whether the entered zip code exists in the array or not, and ...

After successfully executing an AJAX request three times, it encountered a failure

I have implemented a script to send instant messages to my database asynchronously. Here is the code: function sendMessage(content, thread_id, ghost_id) { var url = "ajax_submit_message.php"; var data = { content: content, thread_id: thread_id }; ...

What steps do I need to take to modify the MUI Badge component and insert custom text inside?

Is there a way to replace the number with a label next to a new row added to my table using MUI Badge? For example, instead of displaying a number like 4, I want it to show the word "New" as shown in this image: enter image description here This is the co ...

Receive updates from the backend GraphQL and display them on the frontend React application while executing a mutation

I recently implemented a mutation call from the frontend (react) to the backend, running 5 SQL query files. While the backend processes the queries, the frontend simply shows a "loading..." message. //frontend <Button onClick={()=>addData()} /> C ...

Restricting the number of characters allowed for text messages and keeping track of the count

I am attempting to implement a character limiter for an html textarea using JavaScript. Additionally, I want to include a total character counter. Unfortunately, the code I have written isn't functioning as expected. Can anyone identify where my mist ...

Employing a custom JavaScript function to pass the value as a parameter within the <asp:QueryStringParameter> tag

I have a dilemma with using SelectParameters: <SelectParameters> <asp:QueryStringParameter Name="Store" DbType="String" Direction="Input" QueryStringField="Name" DefaultValue="fetchURL();" ConvertEmptyStringToNull="True" /> </SelectPara ...

Initiate a jQuery modal dialogue box

As an apprentice with no prior experience working with JavaScript, I encountered a problem with my function that calls a popup. The function works fine on the first button, but fails to work on all subsequent buttons. Since the application keeps adding b ...

What strategies can I use to make my div content more adaptable to different screen sizes and

Currently, in my project, I have implemented a layout using the top nav menu (purple part) and the left menu (pink part) as shown in the image. However, I am facing an issue where, upon deleting some content from the view, the pink menu on the left extends ...

In my attempt to assess the correlation between value 1 and a value in the preceding object, I am utilizing the *ngFor directive

Attempting to compare 2 entries in an *ngFor loop. The code should compare the value at the current object to a value at the previous object. <ng-container *ngFor="let item of s_1.comments[0]; index as b"> <article class="message i ...

Using Try and Catch effectively - tips and strategies

As I delve into learning JavaScript on my own, one topic that caught my attention is the try/catch structure. The tutorial I came across only covers how to implement it, but lacks in explaining its practical applications. Is there anyone who can shed som ...

Populate a shopping cart with items using AngularJS

Greetings from an Angular newbie! I'm currently working on developing a shopping cart specifically designed for college students. The objective is to input the name and price of items into a text field and upon clicking a button, have the item added t ...

Iterate over rows in a b-table component in Vue

In the context of Vue bootstrap, a b-table consists of a list with an unknown number of rows. The requirement is to display a remove button only if the email in the row matches that of the currently logged-in user. This functionality currently works for a ...

Obtain the selected option's value using Angular

Having an issue with my user.model.ts file. I have a list of users that I can edit by clicking on a button that filters the user's data and puts it in a bootstrap modal. I'm using [ngModel] in a select tag to get the country of my user, but when ...

Changing an HTML table into an array using JavaScript

Is it possible to transform an HTML table into a JavaScript array? <table id="cartGrid"> <thead> <tr> <th>Item Description</th> <th>Qty</th> <th>Unit Price</th> ...