After creating our middleware, we need to define which routes will be authenticated and which routes won't. Then we have to import the middleware to the router and define it when it is executed:
- Open user.js in the src/router folder.
- In each route object, add a new property called meta. This property will be an object with an authenticated key and a value defined as true. We need to do this to every route – even the children's routes:
import Index from '@/views/user/Index.vue';
import List from '@/views/user/List.vue';
import View from '@/views/user/View.vue';
import Edit from '@/views/user/Edit.vue';
import Create from '@/views/user/Create.vue';
export default [
{
path: '/user',
name: 'user',
component: Index,
meta: {
authenticated: true,
},
children: [
{
path: '',
name: 'list',
component...