From c3b7968a76e09ccf0dacd29e1519f10b1f75a8b2 Mon Sep 17 00:00:00 2001 From: wancat Date: Sun, 10 Sep 2023 20:06:23 +0800 Subject: [PATCH] feat: use vue router to organize pages --- app/package.json | 1 + app/src/App.vue | 67 ++----------------- app/src/components/AuthenticationPart.vue | 10 +-- app/src/components/VisualizationPart.vue | 2 +- app/src/main.js | 22 +++++- .../AuthPage.vue} | 4 +- app/src/views/GamePage.vue | 60 +++++++++++++++++ yarn.lock | 12 ++++ 8 files changed, 110 insertions(+), 68 deletions(-) rename app/src/{AuthenticationPage.vue => views/AuthPage.vue} (72%) create mode 100644 app/src/views/GamePage.vue diff --git a/app/package.json b/app/package.json index d38cd0b..8f5147c 100644 --- a/app/package.json +++ b/app/package.json @@ -19,6 +19,7 @@ "axios": "^1.4.0", "socket.io-client": "^4.7.1", "vue": "^3.3.4", + "vue-router": "^4.2.4", "xterm": "^5.2.1", "xterm-addon-attach": "^0.8.0", "xterm-addon-fit": "^0.7.0" diff --git a/app/src/App.vue b/app/src/App.vue index a4d6e42..767991b 100644 --- a/app/src/App.vue +++ b/app/src/App.vue @@ -1,68 +1,15 @@ - - - + + diff --git a/app/src/components/AuthenticationPart.vue b/app/src/components/AuthenticationPart.vue index 26707d9..3d2da99 100644 --- a/app/src/components/AuthenticationPart.vue +++ b/app/src/components/AuthenticationPart.vue @@ -4,7 +4,7 @@
-

Linux Odysssey

+

Linux Odyssey

- + Log in / Sign up + +
diff --git a/app/src/components/VisualizationPart.vue b/app/src/components/VisualizationPart.vue index f1c9a77..ac9a061 100644 --- a/app/src/components/VisualizationPart.vue +++ b/app/src/components/VisualizationPart.vue @@ -42,7 +42,7 @@ onMounted(() => { }) onUnmounted(() => { - treeRef.value.removeEventListener('mousedown', mouseDownHandler) + treeRef?.value?.removeEventListener('mousedown', mouseDownHandler) }) diff --git a/app/src/main.js b/app/src/main.js index 84f3945..55e4c22 100644 --- a/app/src/main.js +++ b/app/src/main.js @@ -1,4 +1,5 @@ import { createApp } from 'vue' +import { createRouter, createWebHistory } from 'vue-router' import './style.css' /* import the fontawesome core */ @@ -24,7 +25,10 @@ import { faCircleQuestion, faCircleRight, } from '@fortawesome/free-regular-svg-icons' + import App from './App.vue' +import GamePage from './views/GamePage.vue' +import AuthPage from './views/AuthPage.vue' /* add icons to the library */ library.add( @@ -41,4 +45,20 @@ library.add( faTerminal ) -createApp(App).component('font-awesome-icon', FontAwesomeIcon).mount('#app') +const routes = [ + { path: '/', name: 'Home', component: AuthPage }, + { path: '/game', name: 'Game', component: GamePage }, +] + +const router = createRouter({ + history: createWebHistory(), + routes, +}) + +const app = createApp(App) + +app.component('font-awesome-icon', FontAwesomeIcon) + +app.use(router) + +app.mount('#app') diff --git a/app/src/AuthenticationPage.vue b/app/src/views/AuthPage.vue similarity index 72% rename from app/src/AuthenticationPage.vue rename to app/src/views/AuthPage.vue index b7c2280..749522b 100644 --- a/app/src/AuthenticationPage.vue +++ b/app/src/views/AuthPage.vue @@ -1,6 +1,6 @@