title: Using router inside getStaticProps
body: <p>I'm trying to fetch data from an API that varies depending on the URL, trying to do it with withRouter but it seems it won't work inside getStaticProps.</p>
  
  <p>I currently have the following code:</p>
  
  <pre><code>export async function getStaticProps({ router }) {
  const pageRequest = `http://localhost:3000/api/posts/${router.query.pid}`
  const res = await fetch(pageRequest)
  const json = await res.json()
  return {
      props: {
          json,
      },
  }
  }
  </code></pre>
  
  <p>It's returning:</p>
  
  <pre><code>TypeError: Cannot read property 'query' of undefined
  </code></pre>
  
  <p>What's the proper way to get the variable in the URL to use inside getStaticProps?</p>