Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Cómo obtener la URL en getstaticpath nextjs

Tengo problemas para obtener la URL en getStaticPath

 export const getStaticPaths = async (props) => { if (url === 'blah') { return { paths: [ { params: { pid: "create" } }, ], fallback: true, }; }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

tienes que usar getStaticProps() si solo quieres obtener un parámetro

 // pages/posts/[id].js function Post({ post }) { // Render post... } // This function gets called at build time export async function getStaticPaths() { // Call an external API endpoint to get posts const res = await fetch('https://.../posts') const posts = await res.json() // Get the paths we want to pre-render based on posts const paths = posts.map((post) => ({ params: { id: post.id }, })) // We'll pre-render only these paths at build time. // { fallback: false } means other routes should 404. return { paths, fallback: false } } // This also gets called at build time export async function getStaticProps({ params }) { // params contains the post `id`. // If the route is like /posts/1, then params.id is 1 const res = await fetch(`https://.../posts/${params.id}`) const post = await res.json() // Pass post data to the page via props return { props: { post } } } export default Post

pero si también quieres obtener la ruta, puedes usar:

 import { useRouter } from 'next/router' //inside of your component const { asPath } = useRouter()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!