I'm using Vue Rotuer
to control the routes of my project, so I've seen the need to use Navigation Guards
.
<script>
export default{
beforeRouteEnter(to, from, next){
if(to.meta.adminOnly === false){
//alert('f')
next()
}
}
}
</script>
At the same time, I saw a difficulty, because it is a dashboard
, I have the login
page and the other pages. In my page app.vue
I have the following structure.
<template>
<div id="app">
<Menu></Menu>
<router-view class="containerView"></router-view>
</div>
</template>
The component Menu
has all my menu side and top, because I want to change the page, it remains and only the contents change, so I left out the <router-view></router-view>
.
However, I'm having a hard time hiding it, if my user is not logged in (it's on the login page), and I could not solve it, I tried to use beforeRouterEnter
on page app.vue
to validate on what page user is and if the page contains meta adminOnly
, but it did not work, and I did not want to use localStorage
to do this validation, because it would keep my system too insecure.