【问题标题】:Gatsby.js: Preprocessing Relative Path Links in MarkdownGatsby.js:在 Markdown 中预处理相对路径链接
【发布时间】:2018-10-22 08:35:35
【问题描述】:

我想知道是否有一种方法,可能是通过为gatsby-transformer-remark 创建一个插件,可以将相对路径链接转换为使用来自gatsby-link<Link>

例如,假设我在降价文件中有以下内容:

# Here is a Header

Check out my about page:

[About](/about)

如果我导入此降价并显示它:

<div dangerouslySetInnerHTML={{ __html: whatever.childMarkdownRemark.html }} />

然后,当单击“关于”链接时,它会破坏单页应用程序的魔力。

有什么办法可以防止这种情况发生吗?提前致谢。

【问题讨论】:

    标签: reactjs markdown gatsby contentful


    【解决方案1】:

    有一个名为gatsby-plugin-catch-links的插件。

    安装它:

    npm install --save gatsby-plugin-catch-links
    

    将其添加到您的 gatsby-config.js 文件中:

    // In your gatsby-config.js
    plugins: [`gatsby-plugin-catch-links`];
    

    你可以在https://using-remark.gatsbyjs.org/找到一个关于如何在 Gatsby 中使用 remark 的非常好的文档

    对于你的问题,我找到了this article here

    【讨论】:

    • Welp,这很简单,谢谢!明天我将奖励赏金(堆栈溢出至少需要 1 天)。
    • 我的没用。 [link](/some-link) 仍在重新加载/打开新标签
    • 如果我的内部链接是指向其他 .md 文件的链接怎么办?喜欢About
    • @gpbl 您可以将它们与[my link should be called this](../relative_path_to_md_file_from_current_file) 链接。不过,您必须在最后删除 .md
    猜你喜欢
    • 2018-07-11
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 2018-11-06
    相关资源
    最近更新 更多