For those of you who have had the same difficulty with the documentation as I do, follow the code and a brief explanation.
In my main.js
I set globally
router.beforeEach((to, from, next) => {
console.log(to)
if(to.name == 'Dashboard'){
alert('dashboard')
}else{
next()
}
})
With this, it is already possible to restrict access without the permission (I did not do any validation in this example), however, when trying to access via URL
is still possible, however, I was able to solve with the following code in my page Dashboard
<script>
export default{
beforeRouteEnter(to, from, next){
if(to.meta.adminOnly === true){
next('/')
}
}
}
</script>
With this, it would be enough to verify if the user is logged in, if it were not, he would send it back to the login page /
.