I'm puzzled as to why 'i' doesn't recognize the next function, even though I followed a similar video that implemented it without any errors.
import Dashboard from "./Pages/Dashboard.vue";
import Customers from "./Pages/Customers.vue";
EditProfile from "./Pages/EditProfile.vue";
Insurance from "./Pages/Insurance.vue";
Activations from "./Pages/Activations.vue";
Login from "./Pages/Login.vue"
ForgotPassword from "./Pages/ForgotPassword.vue"
MyDashboard from "./Pages_cus/MyDashboard.vue";
MyActivations from "./Pages_cus/MyActivations.vue";
MyEditProfile from "./Pages_cus/MyEditProfile.vue";
NotFound from ./Pages/NotFound.vue';
NetworkError from './Pages/NetworkError.vue'
import { createRouter, createWebHistory } from "vue-router";
const routes = [
{
name: "MyDashboard",
component: MyDashboard,
path: "/my-dashboard",
meta: {
requiresAuth: true,
}
},
{
name: "MyActivations",
component: MyActivations,
path: "/my-activations",
},
{
name: "MyEditProfile",
component: MyEditProfile,
path: "/my-edit-profile",
},
{
name: "Dashboard",
component: Dashboard,
path: "/dashboard",
meta: {
requiresAuth: true,
}
},
{
name: "Customers",
component: Customers,
path: "/customers",
},
{
name: "EditProfile",
component: EditProfile,
path: "/edit-profile",
},
{
name: "Insurance",
component: Insurance,
path: "/insurance",
},
{
name: "Activations",
component: Activations,
path: "/activations",
},
{
name: "Login",
component: Login,
path: "/",
meta: {
requiresAuth: true,
}
},
{
name: "ForgotPassword",
component: ForgotPassword,
path: "/forgot-password",
},
{
name: "404Resource",
component: NotFound,
path: '/404/:resource',
props:true
},
{
name: "NetworkError",
component: NetworkError,
path: '/network-error'
},
{
name: "NotFound",
component: NotFound,
path: '/:catchAll(.*)'
},
];
const router = createRouter({
history: createWebHistory(),
routes,
});
router.beforeEach((to, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
if (localStorage.getItem('token') == null) {
console.log('Hello JS')
next({
path: '/',
params: { nextUrl: to.fullPath }
}) // The error occurs here where 'next' is not recognized as a function
}
else{
next();
}
}
else {
next()
}
})
export default router;