gatsby reloads on clicking link from markdown article a to markdown article b

Created on 8 Jun 2017  路  8Comments  路  Source: gatsbyjs/gatsby

I have a link from one (markdown) post to another. Unlike the links from the index (which are react-router Link components), which trigger flicker-free transitions from the post index to the individual posts, these links trigger a reload.

This is similar to #384, except for some reason I don't entirely understand, that solution works for him. It won't work for me.

I know almost nothing about modern js, react, or gatsby, but I tried adding the following to my custom markdown loader (which otherwise works just fine)

var ReactLink = require('react-router').Link
var React = require('react')
var Link = React.createFactory(ReactLink)
...
var md = markdownIt({
  ....
  replaceLink: function(link, env) {
    return Link({to: link})
  }
})

Which doesn't work. No doubt to actual frontend developers the reason is obvious and comical, but I don't really know what I'm doing here. Nonetheless, I'm hoping it's obvious what I'm _trying_ to do.

My assumption is that something like: when the Link jsx obj is processed, it hooks into the rest of the react code such that when I click the anchor it generates, it knows that it only has to hit the history or some other data stash rather than actually doing a page load. Except in this case, the Link obj isn't being properly serialized into html with the correct onVariousEvent handlers hooked into react, or something.

% gatsby -V
0.12.47

Most helpful comment

For current googlers, send Kyle money so he can finish v1 faster

All 8 comments

Although I know see why the above cannot possibly work (a chunk of v8 runtime memory is not a valid url), is it clear what I'm trying to do? Is it possible to do this? Does it even make sense within the context of react?

I think the solution is something like this (see 'Local Links'), but don't quite know how to implement it. Is that correct, given the current state of gatsby? Will something like that work?

Yup, you want to do something exactly like that!

Thanks. Will close this when/if I get it to work.

great success

haha :-)

For future googlers, in v1, you'll want to use this plugin to accomplish something similar https://www.gatsbyjs.org/docs/packages/gatsby-plugin-catch-links/

For current googlers, send Kyle money so he can finish v1 faster

FYI, the updated link to the gatsby-plugin-catch-links is:

https://www.gatsbyjs.org/packages/gatsby-plugin-catch-links/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magicly picture magicly  路  3Comments

andykais picture andykais  路  3Comments

ferMartz picture ferMartz  路  3Comments

kalinchernev picture kalinchernev  路  3Comments

timbrandin picture timbrandin  路  3Comments