Categories
JavaScript Answers

How to set URL query params in Vue with Vue-Router?

Spread the love

Sometimes, we want to set URL query params in Vue with Vue-Router.

in this article, we’ll look at how to set URL query params in Vue with Vue-Router.

How to set URL query params in Vue with Vue-Router?

To set URL query params in Vue with Vue-Router, we call router.push with an object that has the query property.

For instance, we write

router.push({ path: "register", query: { plan: "private" } });

to call router.push with an object that has the query property to add a query parameter with key plan and value private to the end of the URL with path register.

Conclusion

To set URL query params in Vue with Vue-Router, we call router.push with an object that has the query property.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *