-
Notifications
You must be signed in to change notification settings - Fork 249
Internal link (from markdown) are normal link and trigger full page load #67
Comments
I think this can be solve seperately with #11 I'm working on a branch which use markdown-it-react-renderer to parse markdown from rawBody and replace |
Maintaining a markdown it renderer is a big deal and a time-consuming task. I chosed a different approach by using html-to-react to parse html data from markdown-it and replace 1 down side is they are using lodash without cherry picking, so this will increase bundle size significantly. I tried to send them a PR later for this. For our codebase, there is 1 more thing I have to fix. It is about url prefix (aka basename) Maybe we should use |
basename as been introduced after I asked for it for statinamic, so maybe we should use it now :) We will only need to to replace internal This code should definitely be in the core. |
Haha. Didn't know about that |
Is this a right approach? Should I make an PR for this after big pr landed? |
Looks like a good start since diff seems to be small. |
I raised an issue here https://github.com/mikenikles/html-to-react/issues/22 html2react only have 2 deps: htmlparser2 and lodash (they only use 4-5 functions of lodash) |
Anyway I think on the long term we will need to handle this before client side (because we can). |
Ok. I'll send a PR then. |
Thanks to gatsbyjs/gatsby#93 We can use these LoC to solve this issue: import catchLinks from 'catch-links'
import { browserHistory } from 'react-router'
if (typeof window !== 'undefined') {
catchLinks(window, (href) => {
browserHistory.push(href)
})
} But I would love to have a proper implementation of this using remark, remark-react :) |
That's better than nothing. Will integrate in 0.8.0 |
'catch-links' have a bug with in-page anchor. I have a fork of my own here : https://github.com/thangngoc89/blog/blob/e198ade146e5842b5175f938ddac6018be5563e2/web_modules/app/catchLinks.js |
Forgot to mention that, the above function only work with website that doesn't use pathname. For website that uses pathname (like docs page) you have to prepend pathname or use react-router basename |
Did you opened an issue on the original repo for this bug? |
I planed to send a PR, just forgot. |
react-router does that already on links it handle, so maybe we should do this in markdown content only? |
We should add this logic in PageContainer to scope this in the dangerousHTML part. |
Closed by 07aaa7b |
That's a shame isn't it?
Before handling this, we need to work on #11 (cause this will handle markdown as react components instead of html).
The text was updated successfully, but these errors were encountered: