Skip to content
Discussion options

You must be logged in to vote

Next.js would work fine in this scenario!

goal is to make the dynamic routes work in an exported next js app [...] not possible to know at build time

You'd want to remove getStaticPaths and getStaticProps in this case, as Next.js will automatically export the page statically. You'll then need to read the dynamic parameter from useRouter() and fetch your data client-side.

// pages/product/[name].js
import { useRouter } from "next/router";

const Product = () => {
  const r = useRouter();
  const { name } = r.query;
  if (!name) {
    return (
      <div>
        <p>Loading...</p>
      </div>
    );
  }

  // TODO: data fetching
  return (
    <div>
      <h1>Hi {name}</h1>
      <p>Welc…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@thesobercoder
Comment options

@Timer
Comment options

Timer Aug 3, 2020
Maintainer

@thesobercoder
Comment options

@Timer
Comment options

Timer Aug 3, 2020
Maintainer

@thesobercoder
Comment options

Answer selected by thesobercoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants