If there is no vue routing params, how can I jump to 404 in batches?

/ goods/:id
/ user/:id
if id does not exist, how can I jump to 404 or other pages?
it will not be linked normally. What if the id result on url does not have this id?

I will ask for details when I am in created (). You can judge here to jump if not.
but I have a lot of such routes. Do I have to judge each one?

Mar.05,2021

const router = new VueRouter ({.})

router.beforeEach ((to, from, next) = > {
/.
})


use beforeRouteUpdate, portal: https://router.vuejs.org/zh-c.

const User = {
  template: '...',
  beforeRouteUpdate (to, from, next) {
    // react to route changes...
    // don't forget to call next()
  }
}

1. Reference permission token check
router.beforeEach ((to, from, next) = > {

   if (to.meta.requireAuth) {
       if (store.state.token) {
            next();
        }
    }else {
        next({
            path: '/login',
            query: {redirect:to.fullPath}  
        })
    }
}
else {
    next();
}

})

Menu