I use vue3
and vue-router-4
, and am trying to hide some router links for unauthorized users:
Route file:
{
path: "/users/create",
name: "UserCreate",
meta: {
title: "Create user",
requiresAuth: true
},
component: () =>
import(/* webpackChunkName: "create" */ "@/views/Users/Create.vue")
}
As you can see I have requiresAuth: true
meta in this route, so I want to hide this for guests.
I want to use something like this in my views (v-if
part, which is not working):
<router-link v-if="route.meta.requiresAuth === isLoggedIn()" to="/users/create" class="nav-link"
>Create user</router-link>
Please advise how I can achieve this, and if it's not possible with meta fields
- what is the preferred way to hide links.
P.S. Of course all validation and checks of accesses will be performed at the back-end side, but I still don't want to show user links which they can't view.