Content: Should a trailing slash in the URL affect the API being called to fetch the markdown files?

Created on 16 Jun 2020  路  2Comments  路  Source: nuxt/content

Firstly, my absolute deepest apologies if this is not a nuxt/content related issue, I am trying to rule options out.

I've had this issue for a while now:

Repo steps

If you navigate directly to https://jackdomleo.dev/blog, it works fine. 馃憣 This will redirect to https://jackdomleo.dev/blog/.

If you navigate to https://jackdomleo.dev then click the 'Blog' nav item, no content is shown with no warnings/errors.

I have noticed the content only shows if there is a trailing slash but won't show if there isn't a trailing slash.

Details

nuxt/content version: 1.3.2
Hosting: GitHub Pages
Repo: https://github.com/JDomleo/jackdomleo.dev
File for the /blog page: https://github.com/JDomleo/jackdomleo.dev/blob/master/pages/blog/index.vue

Thank you in advance!!

question

Most helpful comment

Hi @JDomleo

Actually since fetch is asynchronous, mounted is called before fetch on client-side navigation. Making filteredArticles empty since this.articles is still [].

Two solutions:

  • Use a computed property for filteredArticles (I recommend)
  • Call filterArticles in fetch:

`js async fetch () { this.articles = await this.$content('blog', { deep: true }).only(['title', 'date', 'slug', 'description', 'readingTime', 'hashtags']).sortBy('date', 'desc').fetch(); this.filterArticles() }

All 2 comments

Hi @JDomleo

Actually since fetch is asynchronous, mounted is called before fetch on client-side navigation. Making filteredArticles empty since this.articles is still [].

Two solutions:

  • Use a computed property for filteredArticles (I recommend)
  • Call filterArticles in fetch:

`js async fetch () { this.articles = await this.$content('blog', { deep: true }).only(['title', 'date', 'slug', 'description', 'readingTime', 'hashtags']).sortBy('date', 'desc').fetch(); this.filterArticles() }

Thank you @Atinux, this is excellent help!!

Was this page helpful?
0 / 5 - 0 ratings