# Gatsby Rich Text link href is empty

**URL:** <https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348>\
**Category:** Developing with Prismic\
**Tags:** gatsby\
**Created:** [December 24, 2020, 5:58am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348 "2020-12-24T05:58:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![beamer](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/beamer/32/1078_2.png) [@beamer](https://community.prismic.io/u/beamer)\
**Post date:** [December 24, 2020, 5:58am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/1 "2020-12-24T05:58:35Z")

</div>

I've been racking my brain on this. In Prismic I have Rich Text content with links. I've linked them directly to content but the graphql response comes back with `href=""`

Here's my setup:

`gatsby-config.js`

```nohighlight
{
      resolve: "gatsby-source-prismic",
      options: {
        repositoryName: process.env.PRISMIC_REPO,
        accessToken: process.env.PRISMIC_TOKEN,
        schemas: {
          page: require("./src/schemas/page.json"),
          ...
        },
        linkResolver: linkResolver,
        shouldDownloadImage: () => {
          return false
        },
      },
    },

```

`linkResolver.js`

```nohighlight
module.exports = ({ node, key, value }) => doc => {
  console.log("doc", doc)
  if (doc.type === "page") {
    if (doc.uid === "home") {
      return "/"
    } else {
      return `/${doc.uid}`
    }
  }
  return `/${doc.uid}`
}

```

graphql query:

```nohighlight
    items {
      title {
        text
      }
      content {
        html
      }
    }

```

`render`

```auto
<div
  className="font-light prose prose-sm"
  dangerouslySetInnerHTML={{ __html: feature.content.html }}
/>

```

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [December 24, 2020, 10:50pm UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/3 "2020-12-24T22:50:02Z")

</div>

Hey, thanks for reaching out. This is very strange if the response is correct. Is this field inside a Slice or is it a top level field?

Because If it's a top level field, unfortunately the options `raw` and `html` won't be available. Instead you will get a 'spans' object that you can use to detect where a link goes by giving you the start and end of the array, like so:

```
{
  "spans":[
    {
      "type":"hyperlink",
      "start":7,
      "end":11,
      "data":{
        "link_type":"Web",
        "url":"https://sample.com"
      }
    }
  ]
}

```

If this is not the case, I can do a check in your repo. You just need to send me the URL of your repository and the query you are using to get that value

---

<div class="post-metadata">

**Author:** ![beamer](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/beamer/32/1078_2.png) [@beamer](https://community.prismic.io/u/beamer)\
**Post date:** [December 25, 2020, 3:40am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/4 "2020-12-25T03:40:54Z")

</div>

Thanks! This is in a slice!

The repo is `oxfordpennant` and it's Page \> Features Slice

I appreciate the help. I hope it's not something stupid I did.

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [December 29, 2020, 12:00am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/5 "2020-12-29T00:00:24Z")

</div>

Hello, I'm testing your endpoint, and I and indeed seeing something strange in the href response of the linked documents. But before making any further assumptions, I'd like to make a few other tests.

I forgot to ask you about your `gatsby-node` file code. Could you also share this with me? Either here or in a private dm, as you prefer.

How are you handling your dynamic routes? This step is crucial for route generation. Usually, the homepage is a static page inside the `/pages` directory, and all dynamic routes are inside `/templates`

---

<div class="post-metadata">

**Author:** ![Pau](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/pau/32/5422_2.png) [@Pau](https://community.prismic.io/u/Pau)\
**Post date:** [January 14, 2021, 3:51am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/6 "2021-01-14T03:51:29Z")

</div>

Update: The linkResolver that is passed to the gatsby-config.js needs to be a function.

So instead of doing this:

`linkResolver: linkResolver,`

Do this:

`linkResolver: () => (doc) => linkResolver(doc),`

Also, make sure is correctly exported & imported.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [January 15, 2021, 3:51am UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/7 "2021-01-15T03:51:33Z")

</div>

closed on January 15, 2021, 3:51am UTC as resolved,  flag & select 'Something Else' to reopen.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/system/32/1746_2.png) [@system](https://community.prismic.io/u/system)\
**Post date:** [December 9, 2021, 4:46pm UTC](https://community.prismic.io/t/gatsby-rich-text-link-href-is-empty/3348/8 "2021-12-09T16:46:22Z")

</div>

Opened on December 9, 2021, 4:46pm UTC


