박민혁 박민혁 07-17
250717 박민혁 라우터 세팅
@30ebe7c12a5bc3389af8ea6decf3bcbbeab31134
client/views/pages/AppRouter.js
--- client/views/pages/AppRouter.js
+++ client/views/pages/AppRouter.js
@@ -7,6 +7,8 @@
 import FeedBack from "./subPage/FeedBack.vue";
 import Find from "./common/Find.vue";
 import Join from "./common/Join.vue";
+import AppStore from "./AppStore";
+
 
 const routes = [
     {
@@ -29,4 +31,22 @@
     routes,
 });
 
+AppRouter.beforeEach((to, from, next) => {
+  const isLoggedIn = !!AppStore.state.authorization;
+
+  const publicPages = ['/login.page', '/find.page', '/join.page'];
+  const isPublic = publicPages.includes(to.path);
+
+  if (!isLoggedIn && !isPublic) {
+    // 로그인 안 되어 있는데 비공개 페이지 접근 → 로그인 페이지로
+    next({ path: '/login.page' });
+  } else if (isLoggedIn && to.path === '/login.page') {
+    // 로그인 상태에서 로그인 페이지 접근 시 메인으로 리다이렉트
+    next({ path: '/' });
+  } else {
+    next(); // 정상 접근
+  }
+});
+
+
 export default AppRouter;
(파일 끝에 줄바꿈 문자 없음)
client/views/pages/main/Main.vue
--- client/views/pages/main/Main.vue
+++ client/views/pages/main/Main.vue
@@ -57,6 +57,7 @@
 </template>
 
 <script>
+import { mapGetters } from 'vuex';
 
 export default {
     data() {
@@ -84,10 +85,18 @@
     },
     methods: {},
     watch: {},
-    computed: {},
+    computed: {
+    ...mapGetters([
+      'getMemId',
+      'getMemNm',
+      'getMemLoginId'
+    ])
+    },
     components: {},
     created() {},
-    mounted() {},
+    mounted() {
+        console.log("사용자 아이디: " + this.getMemId + " 사용자 이름: " + this.getMemNm + " 사용자 로그인 아이디: " + this.getMemLoginId);
+    },
     beforeUnmount() {},
 };
 
Add a comment
List