소스 검색

:recycle: change route watch to slug watch

tags/0.9.0
J 4 년 전
부모
커밋
8cee4d79d7
1개의 변경된 파일11개의 추가작업 그리고 8개의 파일을 삭제
  1. 11
    8
      vue-theme/src/pages/single.vue

+ 11
- 8
vue-theme/src/pages/single.vue 파일 보기

@@ -66,6 +66,9 @@ export default {
66 66
         sidebar() {
67 67
             return true
68 68
         },
69
+        slug() {
70
+            return this.$route.params.slug
71
+        },
69 72
         type() {
70 73
             // Checks for type and fixes Episodes route edge case
71 74
             return this.$route.params.type
@@ -191,7 +194,7 @@ export default {
191 194
             // Find the single post from api if it's not already in state
192 195
             // Then add it to our list
193 196
             let singlePostData = allPostsOfTypeInStore.filter(
194
-                post => post.slug == this.$route.params.slug,
197
+                post => post.slug == this.slug,
195 198
             )[0]
196 199
 
197 200
             // Look if it exists before you try and load everything!
@@ -202,7 +205,7 @@ export default {
202 205
                     { sortType: null, params: null }
203 206
                 )
204 207
                 singlePostData = res.filter(
205
-                    post => post.slug == this.$route.params.slug,
208
+                    post => post.slug == this.slug,
206 209
                 )[0]
207 210
             }
208 211
 
@@ -223,13 +226,13 @@ export default {
223 226
     },
224 227
     watch: {
225 228
         // This fires navigating to and away
226
-        $route(to) {
229
+        slug(newSlug, oldSlug) {
227 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 238
     created() {

Loading…
취소
저장