added vue component

This commit is contained in:
2023-09-15 19:58:59 +02:00
parent b3061ad79a
commit 018bbf3918
34 changed files with 4134 additions and 458 deletions
+60
View File
@@ -0,0 +1,60 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
name: 'home',
component: HomeView,
meta: { requiresAuth: true }, // Add a meta field to indicate that this route requires authentication
},
{
path: '/feeds',
name: 'feeds',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/FeedView.vue'),
meta: { requiresAuth: true }, // Add a meta field to indicate that this route requires authentication
},
{
path: '/about',
name: 'about',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import('../views/AboutView.vue'),
meta: { requiresAuth: true }, // Add a meta field to indicate that this route requires authentication
},
{
path: '/login',
name: 'login',
component: () => import('../views/LoginView.vue')
},
]
})
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
// TODO Check if the user is authenticated (e.g., check for a valid token)
let isAuthenticated = false;
if (localStorage.getItem("user-token") != null){
isAuthenticated = true;
}
if (!isAuthenticated) {
// Redirect to the login page
next('/login');
} else {
// Proceed to the protected route
next();
}
} else {
// For routes that don't require authentication, proceed without checking
next();
}
});
export default router