vuehaus
vuehaus copied to clipboard
Add fullPath watcher to differentiate between front page and search results?
I needed to add this to ETC in the watch
section on the front page:
'$route.fullPath'(to, from) {
if (to == '/' && from.includes('?s=')) {
this.$store.dispatch('LOAD_AND_REPLACE_QUERYDATA', {
path: '/'
})
} else if (to.includes('?s=') && from == '/') {
this.$store.dispatch('LOAD_AND_REPLACE_QUERYDATA', {
path: to
})
}
}
This ensures that a page's query data is reloaded when switching from the front page (/
) to a search results page (?s=search-term
) or vice-versa. Without this watcher, moving between those two pages is broken.
I'm adding it on ID10T since I'm running into the same issue there, too, and was wondering if we should just add it to the boilerplate. Thoughts @johndigital @lwaldner @drewbaker ?
I wonder if we should just make a page search
that we use for all search results? I've always thought it was weird how you could do a search on any page in WordPress. If we did that, then it would be easier to deal with right?
It'd be much easier to deal with! We could still have the search term as a query param but have the search live on its own page - I think that'd save us some headache in the long run.
Let's talk about this when we do the ID10T tech review. I just built a search for Humble and took a pretty different approach, so I think it will be good for us to all go over the options together and decide best practice.