How to clear query string during router redirect

Give I have a route like this:

{
  path: '/forward/:id',
  name: 'link-forwarder',
  redirect: linkForwarder,
},

Which calls a linkForwarder function like this:

export default function linkForwarder(route) {
   // do something with route.query and then save it in store
  
  // now clear query, something like
  // router.replace({ query: {} })

  return route.params.id
}

Unfortunately I don’t have access to router in linkForwarder, just route. Can I use some middleware approach that will remove everything from the query string before continuing?

Hello,

middlewares seem to be the way to go,
You can try something like this

{
  path: '/forward/:id',
  name: 'link-forwarder',
  beforeEnter: (to, from, next) => {
    // do something with to.query and then save it in store
    next(Object.assign({}, to, { query: {} }))
  }
},

SOLVED: solution was to user beforeEnter instead of redirect

  beforeEnter: (to, from, next) => {
    next(linkForwarder(to))
  },

Thanks @nicolas