1

I cannot retrive prev and next article with nuxt content.

in my slug page I have this code:

async asyncData({ $content, params }) {
  const article = await $content('onstep', params.slug).fetch();

  const [prev, next] = await $content('onstep')
    .only(['title', 'slug', 'order'])
    .sortBy('order', 'desc')
    .surround(params.slug)
    .fetch();

  return {
    article,
    prev,
    next
  };
},

but prev and next returning null, oneother things I don't understand, is the

.surround(params.slug)

Why is used params.slug???

If I use postman to http://localhost:3000/_content/onstep?only=title&only=slug&only=order I get the list of my article, in my case I use a tag called order to order how the content should be seen.

In my project I need to use trailingSlash to true, but if I console.log params.slug is without trailingSlash

any suggestions?

kissu
  • 40,416
  • 14
  • 65
  • 133
Stefano Martini
  • 408
  • 2
  • 17
  • Params should not include any trailing slash so far. You're maybe looking for `this.$route.path`? Also, do you have a [repro] for this one? – kissu Oct 14 '21 at 09:06
  • if I use ` this.$route.path ` I get error Unexpected this in asyncData,I have no idea how and where I can send you a minimal example project. The strange thing I seen, If I remove surround method I get the list of all articles as I expected... – Stefano Martini Oct 14 '21 at 09:23
  • If you're using `asyncData`, you need to use the context, hence writing it this way: ` asyncData({ route }) {`. For a minimal project, either share your github repo or create a new project reproducing the issue. – kissu Oct 14 '21 at 09:29

1 Answers1

0

my fault, and one day gone...

Having some problems with google crawler I addes the / to any slug, so nuxt will try to find my-slug but in all articles the slug are my-slug/ edited all the slug and now work perfectly

Stefano Martini
  • 408
  • 2
  • 17