simpixelated / san-diego-downtown-mobility-plan

Advocacy for the San Diego Downtown Mobility Plan
http://simpixelated.github.io/san-diego-downtown-mobility-plan/
MIT License
0 stars 0 forks source link

prevent links causing full page reload #22

Open simpixelated opened 8 years ago

simpixelated commented 8 years ago

Local links By default, links to other pages in your site from markdown-generated HTML will cause a full refresh of the page, defeating the purpose of a SPA. You can fix that with the catch-links node module. Try something like this in wrappers/md.js:

import catchLinks from 'catch-links';

// inside MarkdownWrapper component
contextTypes: {
  router: React.PropTypes.object.isRequired
},

componentDidMount: function() {
  const _this = this;
  catchLinks(this.refs.markdown, function(href) {
    _this.context.router.push(href);
  });
},

render: function() {
  const htmlFromMarkdown = this.props.route.data.body;
  // ...
  <div
    ref="markdown"
    dangerouslySetInnerHTML={{__html: htmlFromMarkdown}}
  />
  // ...
}

https://blog.scottnonnenberg.com/practical-gatsby-js/