Make globale funtion for beforeEnter in router file

In my router.js file i need to add a test beforeEnter to the route, if the token is ok it next(’/compoent ') else redirect the user to the router,i have many routes, i want to use a global function to call it for each beforeEnter, i thinked to create a function in router file, but i can’t use the parameters of beforeEnter(to,from,next) in my function and to make next("/"); dynamique, some ona hase any idea or hint?

{ path: "/item/index", name: "ItemIndex", component: ItemIndex, 
        beforeEnter: (to, from, next) => {
      if (Vue.$cookies.get("jwt")) {
        var base64Url = Vue.$cookies.get("jwt").split(".")[1];
        var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
        var jsonPayload = decodeURIComponent(
          atob(base64)
            .split("")
            .map(function(c) {
              return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
            })
            .join("")
        );
        JSON.parse(jsonPayload).exp;
        Vue.exp = JSON.parse(jsonPayload).exp;
        if (Vue.exp < Date.now() / 1000 || Vue.exp == "") {
          console.log('Vue.exp :',Vue.exp )
          next("/");
        }
      } 
       next();
    },