2

我想在 Gatsby 博客中设置分页。在我的pages/index.js页面中,我存储了帖子、“分块”帖子(例如每页 4 个帖子的块)和当前页码:

this.state = {
  allPosts: props.data.allMarkdownRemark.edges,
  postChunks: [],
  currentpage: 0,
};

目前,如果我localhost:8000指向这个组件,加载前 4 个帖子并显示它们。我希望能够去localhost:8000/page2并让这条路线指向同一个组件。目前它带我到404页面。如何修改路由以使所有pageX路由都转到同一个index.js组件?

4

2 回答 2

3

使用 Gatsby,您可以通过编程方式创建路线。

查看 gatsby-paginate,它可以轻松创建分页索引页面https://github.com/pixelstew/gatsby-paginate/

于 2017-11-10T19:11:22.387 回答
-1

如果你使用 react-router 你可以使用<Route path="/" component={Blog} />

从根“/”开始的任何路径都将转到同一个博客组件(您可以通过声明“确切路径”来避免这种情况)。我猜你可以使用 url 来确定你显示的块。

于 2017-11-08T21:19:45.287 回答