Home > Net >  Adding default query to all router links in Vue?
Adding default query to all router links in Vue?

Time:11-04

I'm trying to find a way to add default query to all router-links on a page (in all components that it has)?

For example, I want all links on a page to end with argument: utm_campaign=from_our_friends.

And this page uses components that are also used by other pages.

CodePudding user response:

You can add a navigation guard to the page component that adds an extra query param to the next destination:

beforeRouteLeave(to, from, next) {
  const query = { ...to.query, utm_campaign: "from_our_friends" };
  next({ query });
}
  • Related