Selaa lähdekoodia

修正了重复的NotFound组件,更新了路由

Nivek 2 vuotta sitten
vanhempi
commit
e450ccba2d
5 muutettua tiedostoa jossa 42 lisäystä ja 52 poistoa
  1. 1 1
      components.d.ts
  2. 0 21
      src/components/NotFound.vue
  3. 11 9
      src/router/index.ts
  4. 30 0
      src/views/NotFound.vue
  5. 0 21
      src/views/user/NotFound.vue

+ 1 - 1
components.d.ts

@@ -36,7 +36,7 @@ declare module 'vue' {
     ElUpload: typeof import('element-plus/es')['ElUpload']
     Footer: typeof import('./src/components/Footer.vue')['default']
     Header: typeof import('./src/components/Header.vue')['default']
-    NotFound: typeof import('./src/components/NotFound.vue')['default']
+    NotFound: typeof import('./src/views/NotFound.vue')['default']
     OrderItem: typeof import('./src/components/OrderItem.vue')['default']
     ProductItem: typeof import('./src/components/ProductItem.vue')['default']
     RouterLink: typeof import('vue-router')['RouterLink']

+ 0 - 21
src/components/NotFound.vue

@@ -1,21 +0,0 @@
-<script setup lang="ts">
-
-</script>
-
-<template>
-  <el-result
-      icon="error"
-      title="错误"
-      sub-title="您访问的页面不存在"
-    >
-    <template #extra>
-      <router-link to="/home">
-        <el-button type="primary">回到主页</el-button>
-      </router-link>
-    </template>
-  </el-result>
-</template>
-
-<style scoped>
-
-</style>

+ 11 - 9
src/router/index.ts

@@ -91,15 +91,17 @@ const router = createRouter({
                 }
             },
         ]
-    },
-        {
-            path: '/404',
-            name: '404',
-            component: () => import('../components/NotFound.vue'),
-            meta: {
-                title: '404'
-            }
-        }]
+    }, {
+        path: '/404',
+        name: '404',
+        component: () => import('../views/NotFound.vue'),
+        meta: {
+            title: '404'
+        }
+    }, {
+        path: '/:catchAll(.*)',
+        redirect: '/404'
+    }]
 })
 
 router.beforeEach((to, _, next) => {

+ 30 - 0
src/views/NotFound.vue

@@ -0,0 +1,30 @@
+<script setup lang="ts">
+
+</script>
+
+<template>
+  <el-main class="main-frame">
+    <el-result
+        icon="error"
+        title="错误"
+        sub-title="您访问的页面不存在"
+    >
+      <template #extra>
+        <router-link to="/home">
+          <el-button type="primary">回到主页</el-button>
+        </router-link>
+      </template>
+    </el-result>
+  </el-main>
+</template>
+
+<style scoped>
+.main-frame {
+  width: 100%;
+  height: 100%;
+
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+</style>

+ 0 - 21
src/views/user/NotFound.vue

@@ -1,21 +0,0 @@
-<script setup lang="ts">
-
-</script>
-
-<template>
-  <el-result
-      icon="error"
-      title="错误"
-      sub-title="您访问的页面不存在"
-    >
-    <template #extra>
-      <router-link to="/home">
-        <el-button type="primary">回到主页</el-button>
-      </router-link>
-    </template>
-  </el-result>
-</template>
-
-<style scoped>
-
-</style>