【发布时间】:2021-03-30 10:33:24
【问题描述】:
我想获取每个页码的数据。
例如: 网址:https://myapp.com/films?pagenumber=1
export async function getStaticProps(data) {
console.log(data.slugs.pagenumber)//1
}
【问题讨论】:
标签: reactjs next.js server-side-rendering
我想获取每个页码的数据。
例如: 网址:https://myapp.com/films?pagenumber=1
export async function getStaticProps(data) {
console.log(data.slugs.pagenumber)//1
}
【问题讨论】:
标签: reactjs next.js server-side-rendering
你可以使用getInitialProps
import App from 'next/app'
class Application extends App {
...
}
Application.getInitialProps = async ({ ctx }) => {
return { pathname: ctx.asPath }
}
export default Application
现在在Application 中你有this.props.pathname,如何解析它取决于你(你可以使用new URLSearchParams - https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams)
【讨论】: