Navigating with router.push in Vue.js to the same path but with different query parameters

The existing URL is

/?type=1

I am attempting to implement router.push on this specific page.

this.$router.push('/?type=2');

However, it results in a NavigationDuplicated error.

I prefer not to utilize parameters such as

/:type

Answer №1

Aliraza has already provided a response to your inquiries. However, I would like to share this answer in response to your comments about components not rerendering. In order to trigger rerendering of components, you must watch for changes in parameters like so:

 watch: {
    '$route.params': 'functionToRunWhenParamsChange',
  }

Answer №2

This is due to the fact that it mirrors your current route. If there is a variance in the value of type, you will not encounter the NavigationDuplicated error. You can also structure separate queries as shown below to ensure clarity for the framework:

this.$router.push({
   path: '/',
   query: { type: 2 },
});

Answer №3

<router-view :key="$route.fullPath"

Answer №4

For further details on this issue, please refer to this GitHub thread. The problem seems to arise when utilizing this.$router.replace, which likely stems from the same underlying cause as using this.$router.push. A recommended workaround is to append an empty catch method after the $router call:

this.$router.push('/?type=2').catch(err => {})

UPDATE

An alternative approach is to pass query parameters in an object format to the second parameter of this.$router.push:

this.$router.push({ query: { type: 2 } })

Answer №5

To update the URL and reload a webpage, use this syntax:

window.location.href = "new-url"

Good to go!

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 is the best way to search for documents that have all conditions met within a sub-array entry?

My rolesandresponsibilities collection document is displayed below: [{ "_id": { "$oid": "58b6c380734d1d48176c9e69" }, "role": "Admin", "resource": [ { "id": "blog", "permissions": [ " ...

There are three pop-up windows displayed on the screen. When each one is clicked, they open as intended, but the information inside does not

Every button triggers a unique modal window Encountering an unusual problem with Bootstrap 5 modal functionality. Within a webpage displaying a list of database entries (refer to the screenshot), each entry features three buttons to open corresponding mod ...

Enhance user experience with Bootstrap by automatically adding a frame around a card upon clicking

Hello everyone! I am a beginner in the Angular/Web Development world and I am currently working on improving my HTML/CSS skills. While using Bootstrap in my Angular project, I ran into a challenge that I couldn't figure out on my own. I have implement ...

Vue-CLI encounters a hiccup while attempting to fetch an image from the assets directory

Currently working with vue-cli 3 and I've implemented this style: .login-page { ... background: url("~@/assets/login-bg.jpg") no-repeat; background-size: cover; background-position: center; ... } However, upon running yarn serve, an error ...

I'm interested in learning the best way to insert the images from this JSON file into the corresponding div elements

I have completed developing a clone of an Instagram web page. Although I can retrieve data from the JSON file and insert it into the <img> tag, I am facing difficulty in displaying each image above its respective .below-image div with consistent spac ...

Puppeteer App Error: An error has been detected on the client side

I am facing an issue using Puppeteer with NEXT.JS while attempting to capture a screenshot. Everything runs smoothly on localhost, but in production, the captured image comes back with the following error message: Application error - a client-side exceptio ...

Is there a way I can invoke my function prior to the form being submitted?

For the last couple of days, I've been struggling to make this code function properly. My goal is to execute a function before submitting the form to verify if the class for each variable is consistent. You can access my code here. Any assistance you ...

TinyMCE generates HTML code with embedded tags

Hey there, I'm currently facing an issue with TinyMCE that I just can't seem to solve. I've browsed through some related posts but haven't found a solution that works for me... For example: When I input something in my back office, ...

Utilizing an external JavaScript file for developing applications on Facebook

I am looking to incorporate external JavaScript into my Facebook application development. Specifically, I am hoping to utilize the Ajax tab feature in my application. ...

Creating the x and y coordinates for drawImage in HTML5

Understanding the x and y axis has posed a challenge for me: //retrieve last known x and y coordinates ...code var p = $("#draggable"); var offset = p.offset(); var x = offset.left; var y = offset.top; //establish new font siz ...

Incorporating '@vite-pwa/nuxt' into a nuxt 3 project leads to hydration issues

I have a Nuxt 3 website that I want to make PWA enabled. To achieve this, I am utilizing '@vite-pwa/nuxt'. However, after adding the package and enabling PWA in my nuxt.config.ts file, I encountered two issues: Hydration errors occur when refre ...

Leveraging the power of axios.all for dynamic operations

Is there a way to efficiently reuse the same Vue-component for both editing and creating new users? While working with vue-router, I have implemented a beforeRouteEnter method to fetch data via API. Depending on whether an ID is set in the URL parameter, ...

Utilizing Puppeteer to Navigate and Interact with Elements Sharing Identical Class Names

I am new to Puppeteer and NodeJs, and I am attempting to scrape a specific website with multiple posts that contain a List element. Clicking on the List element loads the comment section. My question is: I want to click on all the list elements (since th ...

How can I write this to function on click events?

Could someone please help me with a simple question I have? I am struggling to properly write the code. $wish_1='<span onclick=alert("Register or Login Now");></span>'; The issue is that spaces are not working and using ' also ...

Guide to redirecting to another page with parameters in React

After successfully integrating Stripe with React and processing a payment, I am trying to redirect to another page. await stripe .confirmCardPayment(CLIENT_SECRET, { payment_method: { card: elements.getElement(CardElement), ...

general structure used to activate every page in vue 3

AppTopbar.vue <Dropdown v-model="selected" :options="storesLists" @change="onChange" optionLabel="name" :filter="true" /> onChange(event) { console.log(event.value.value); localSt ...

Ensure that it is safe to bypass Vue's built-in sanitization on this specific Vue component for the href attribute

I encountered an issue with a .vue file that contains an anchor tag as shown below: <a class="login_class" :href="loginUrl">Use Universal Login</a> When running Sonar, it raises a warning regarding the :href attribute: En ...

Organizing subcategories within a dropdown checklist

I am currently working on a list that utilizes dropdownchecklist and I am looking to create subgroups from the elements in the list. The goal is that by clicking on a subgroup checkbox, it will automatically check all elements associated with it. Below is ...

Having trouble connecting to the node server from the vue.js development environment

I am currently working on a Vue project where the source code is located in the vue app directory and the backend file is server.js: /dist /src server.js When I start the project using npm run serve, Vue.js runs on port 8080. However, when I start serve ...

What changes can I make to my method in order to utilize async/await?

Within my React application, I have implemented a post request to the server using axios: onSubmit = async (results) => { try { const response = await axios.post("http://localhost:8080/simulate/", results); this.setState({results: ...