Sfoglia il codice sorgente

:recycle: change route watch to slug watch

tags/0.9.0
J 4 anni fa
parent
commit
8cee4d79d7
1 ha cambiato i file con 11 aggiunte e 8 eliminazioni
  1. 11
    8
      vue-theme/src/pages/single.vue

+ 11
- 8
vue-theme/src/pages/single.vue Vedi File

66
         sidebar() {
66
         sidebar() {
67
             return true
67
             return true
68
         },
68
         },
69
+        slug() {
70
+            return this.$route.params.slug
71
+        },
69
         type() {
72
         type() {
70
             // Checks for type and fixes Episodes route edge case
73
             // Checks for type and fixes Episodes route edge case
71
             return this.$route.params.type
74
             return this.$route.params.type
191
             // Find the single post from api if it's not already in state
194
             // Find the single post from api if it's not already in state
192
             // Then add it to our list
195
             // Then add it to our list
193
             let singlePostData = allPostsOfTypeInStore.filter(
196
             let singlePostData = allPostsOfTypeInStore.filter(
194
-                post => post.slug == this.$route.params.slug,
197
+                post => post.slug == this.slug,
195
             )[0]
198
             )[0]
196
 
199
 
197
             // Look if it exists before you try and load everything!
200
             // Look if it exists before you try and load everything!
202
                     { sortType: null, params: null }
205
                     { sortType: null, params: null }
203
                 )
206
                 )
204
                 singlePostData = res.filter(
207
                 singlePostData = res.filter(
205
-                    post => post.slug == this.$route.params.slug,
208
+                    post => post.slug == this.slug,
206
                 )[0]
209
                 )[0]
207
             }
210
             }
208
 
211
 
223
     },
226
     },
224
     watch: {
227
     watch: {
225
         // This fires navigating to and away
228
         // This fires navigating to and away
226
-        $route(to) {
229
+        slug(newSlug, oldSlug) {
227
             // Only load post data when navigating TO a single page
230
             // Only load post data when navigating TO a single page
228
-            const path = to.fullPath.split('/').filter(p => p)
229
-            console.log('single to :', to)
230
-            if (path.length < 2 || !postTypes.includes(to.params.type) || !to.params.sortBy) return
231
-            this._clearHero(this.$store)
232
-            this.loadPostData()
231
+            console.log('single :', newSlug, oldSlug)
232
+            if(newSlug && !oldSlug) {
233
+                this._clearHero(this.$store)
234
+                this.loadPostData()
235
+            }
233
         },
236
         },
234
     },
237
     },
235
     created() {
238
     created() {

Loading…
Annulla
Salva