withastro / docs

Astro documentation
https://docs.astro.build/
MIT License
1.34k stars 1.51k forks source link

Dynamic routing #2794

Closed angepili closed 1 year ago

angepili commented 1 year ago

Using this code by official documentation

---
import { useStoryblokApi } from '@storyblok/astro'
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro'

export async function getStaticPaths() {
  const sbApi = useStoryblokApi();

  const { data } = await sbApi.get("cdn/stories", {
    content_type: "post",
    version: "draft",
  });

  const stories = Object.values(data.stories);

  return stories.map((story) => {
    return {
      params: { slug: story['slug'] },
    };
  });
}

const sbApi = useStoryblokApi();
const { slug } = Astro.params;
const { data } = await sbApi.get(`cdn/stories/${slug}`, {
  version: "draft",
});

const story = data.story;
---

<html lang="en">
  <head>
    <title>Storyblok & Astro</title>
  </head>
  <body>
    <StoryblokComponent blok={story.content} />
  </body>
</html>

And using this file structure: src/pages/post/[...slug].astro

I've the follow error:


node:internal/process/promises:279
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
  code: 'ERR_UNHANDLED_REJECTION'
}```
sarah11918 commented 1 year ago

Hi @angepili - We've been trying to reproduce your error, but we're not sure what might be causing this! Are you still having a problem with your code? I've checked with our Storyblock friends, and they also think your code looks correct, which probably means our docs are showing the correct code to use.

If you're still having trouble, please visit us in the Astro Discord to help troubleshoot! https://astro.build/chat. I'm going to close this docs issue for now, since we think the docs are ok! But, please do reopen if you can't get help in the Discord and you discover that there is something wrong with the docs that we can fix!