getPathFromContext

Return the path (slug) from getStaticProps or getServerSideProps context.


const slug = drupal.getPathFromContext(
context,
options?: {
pathPrefix,
}
): string
  • context: GetStaticPropsContext | GetServerSidePropsContext
    • Required
    • The context from getStaticProps or getServerSideProps.
  • options
    • Optional
    • pathPrefix: string: Set the pathPrefix if you're calling from a subdir. Example: for /articles/[...slug].tsx, use pathPrefix: "/articles".

Examples

  • Get the path (slug) from getStaticProps context.
export async function getStaticProps(context) {
const slug = await drupal.getPathFromContext(context)
}