user74843
user74843

Reputation: 701

gatsbyJS Link: want to use backticks in to property, but cannot

I want to write something like this in my Gatsbyjs Link tag:

 <Link to=`/${this.props.latestPost.node.slug}`>Click Here</Link>

but it's not working, and my code looks like this:

enter image description here

Is there some way I could use a javascript expression inside the 'to' property? I want the slug to be dynamic, as the Link tag is for a 'recent posts' set of links, that will regularly update.

Upvotes: 1

Views: 176

Answers (1)

Fabian Schultz
Fabian Schultz

Reputation: 18556

You need to escape it as Javascript:

<Link to={`/${this.props.latestPost.node.slug}`}>Click Here</Link>

Upvotes: 1

Related Questions