Vue PWA mylog Source Code

router

그랜파 개발자 2024. 11. 8. 16:00

router/index.js

// src/router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store';

import HomeView from '../views/HomeView.vue'
import LoginView from '../views/LoginView.vue'
import RegisterView from '../views/RegisterView.vue'
import ProfileView from '../views/ProfileView.vue'
import WriteMyLogView from '../views/WriteMyLogView.vue'
import EditMyLogView from '../views/EditMyLogView.vue'

import MyMyLogsView from '../views/MyMyLogsView.vue'
import MyLogView from '../views/MyLogView.vue'
import UserMyLogsView from '../views/UserMyLogsView.vue'
import SearchMyLogsView from '../views/SearchMyLogsView.vue'
import SubscriptionsView from '../views/SubscriptionsView.vue'
import ReadersView from '../views/ReadersView.vue'
import NotificationView from '../views/NotificationView.vue'
import ManageView from '../views/ManageView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/register',
    name: 'register',
    component: RegisterView
  },
  {
    path: '/profile',
    name: 'profile',
    component: ProfileView,
    meta: { requiresAuth: true }
  },
  {
    path: '/write',
    name: 'write',
    component: WriteMyLogView,
    meta: { requiresAuth: true }
  },
  { 
    path: '/mylog/:id', 
    name: 'mylog', 
    component: MyLogView
  },
  {
    path: '/mylog/edit/:mylog',
    name: 'edit',
    component: EditMyLogView,
    props: true,
  },  
  {
    path: '/mylogs',
    name: 'mylogs',
    component: MyMyLogsView,
    meta: { requiresAuth: true }
  },
  {
    path: '/userlogs/:userId',
    name: 'userlogs',
    component: UserMyLogsView
  },
  {
    path: '/search',
    name: 'search',
    component: SearchMyLogsView
  },
  {
    path: '/subscribing',
    name: 'subscribing',
    component: SubscriptionsView,
    meta: { requiresAuth: true }
  },
  {
    path: '/subscriber',
    name: 'subscriber',
    component: ReadersView,
    meta: { requiresAuth: true }
  },
  {
    path: '/notification',
    name: 'notification',
    component: NotificationView,
    meta: { requiresAuth: true }
  },
  {
    path: '/manage',
    name: 'manage',
    component: ManageView,
    meta: { requiresAuth: true  }
  },
  {
    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(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {

  const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
  const user = store.state.auth.user;

  if (requiresAuth && !user) {
    next('/login');
  } else {
    next();
  }
});

export default router

'Vue PWA mylog Source Code' 카테고리의 다른 글

store/mylogs.js  (0) 2024.11.11
store/fcm.js  (0) 2024.11.09
store/auth.js  (0) 2024.11.09
store/index.js  (0) 2024.11.09
firebase.js  (0) 2024.11.07