Skip to content

Commit 24350c1

Browse files
committed
Properly convert product name to slug on search page
1 parent 0c47885 commit 24350c1

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

pages/search.vue

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<NuxtLink
99
class="text-black cursor-pointer hover:underline"
1010
:to="{
11-
path: '/product/' + item.product_name,
11+
path: '/product/' + convertProductNameToSlug(item.product_name),
1212
query: { id: item.objectID },
1313
}"
1414
>
@@ -33,12 +33,6 @@
3333
</template>
3434

3535
<script>
36-
// TODO
37-
/*
38-
Replace empty spaces with dash (-)
39-
40-
const trimmedProductName = product_name.replace(/ /g, '-');
41-
*/
4236
import {
4337
AisInstantSearchSsr,
4438
AisRefinementList,
@@ -72,12 +66,6 @@ export default {
7266
}),
7367
],
7468
layout: 'Layout',
75-
serverPrefetch() {
76-
return this.instantsearch.findResultsState(this).then((algoliaState) => {
77-
this.$ssrContext.nuxt.algoliaState = algoliaState
78-
})
79-
},
80-
8169
head() {
8270
return {
8371
link: [
@@ -95,5 +83,16 @@ export default {
9583
9684
this.instantsearch.hydrate(results)
9785
},
86+
methods: {
87+
convertProductNameToSlug(productName) {
88+
const productNameSlug = productName.replace(/ /g, '-').toLowerCase()
89+
return productNameSlug
90+
},
91+
},
92+
serverPrefetch() {
93+
return this.instantsearch.findResultsState(this).then((algoliaState) => {
94+
this.$ssrContext.nuxt.algoliaState = algoliaState
95+
})
96+
},
9897
}
9998
</script>

0 commit comments

Comments
 (0)