问题描述
我遇到了一些奇怪的事情,并且尝试了许多变通方法,但没有成功。
我试图像这样在模板的网址后附加“博客”。
createPage({
path: /blog${node.fields.slug},// this line
component: blogPost,context: {
slug: post.node.fields.slug,prevIoUs,next,},})
哪个工作正常。因此,我使用相同的方法来解释下一个/上一个链接。
<Link to={blog${next.fields.slug}} rel="prev">
(下一个示例)
但是当我去看一篇文章时blog/category/hello-category
,然后尝试单击下一篇或上一篇文章,例如/blog/category/hello-category2
,该路径会附加当前路径和下一个路径-就像这样。
/blog/category/hello-category/blog/category/hello-category2
有人可以帮忙吗?
谢谢。
解决方法
缺少斜杠导致了此问题。
<Link to={
/ blog $ {next.fields.slug} } rel="prev">
“开头没有斜线,它假定链接是相对于根的。在这方面,它的行为与普通HTML链接相同。”