Преглед на файлове

Настройка правильных редиректов роутера

Book Pauk преди 3 години
родител
ревизия
6053ca6c0e
променени са 3 файла, в които са добавени 29 реда и са изтрити 2 реда
  1. 19 1
      client/components/CardIndex/CardIndex.vue
  2. 9 0
      client/components/Reader/Reader.vue
  3. 1 1
      client/router.js

+ 19 - 1
client/components/CardIndex/CardIndex.vue

@@ -1,6 +1,5 @@
 <template>
     <div>
-
         <router-view v-slot="{ Component }">
             <keep-alive>
                 <component :is="Component" />
@@ -38,6 +37,17 @@ class CardIndex {
     _options = componentOptions;
     selectedTab = null;
 
+    created() {
+        this.$watch(
+            () => this.$route.path,
+            (newValue) => {
+                if (newValue == '/cardindex' && this.isReader) {
+                    this.$router.replace({ path: '/reader' });
+                }
+            }
+        )
+    }
+
     mounted() {
         this.setTabByRoute(this.curRoute);
     }
@@ -60,11 +70,19 @@ class CardIndex {
         }
     }
 
+    get mode() {
+        return this.$store.state.config.mode;
+    }
+
     get curRoute() {
         const m = this.$route.path.match(/^(\/[^/]*\/[^/]*).*$/i);
         return (m ? m[1] : this.$route.path);
     }
 
+    get isReader() {
+        return (this.mode !== null && (this.mode == 'reader' || this.mode == 'omnireader' || this.mode == 'liberama.top'));
+    }
+
 }
 
 export default vueComponent(CardIndex);

+ 9 - 0
client/components/Reader/Reader.vue

@@ -288,6 +288,15 @@ class Reader {
 
         this.lastActivePage = false;
 
+        this.$watch(
+            () => this.$route.path,
+            (newValue) => {
+                if (newValue == '/reader') {
+                    this.updateRoute();
+                }
+            }
+        );
+
         this.debouncedSetRecentBook = _.debounce(async(newValue) => {
             const recent = this.mostRecentBook();
             if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {

+ 1 - 1
client/router.js

@@ -35,7 +35,7 @@ const myRoutes = [
     ['/settings', Settings],
     ['/help', Help],
     ['/404', NotFound404],
-    ['/(.*)', null, null, '/cardindex'],
+    ['/:pathMatch(.*)*', null, null, '/cardindex'],
 ];
 
 let routes = {};