rsnext/examples/dynamic-routing
Luis Alvarez D 57f72eac9e Add catch all routes example and a link to it in docs (#10202)
* Added example

* Updated readme of the dynamic-routing example

* Updated catch all docs

* Simplified example

* Update examples/catch-all-routes/README.md

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

Co-authored-by: Joe Haddad <timer150@gmail.com>
2020-01-27 13:29:05 -05:00
..
components Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
pages Improve linting rules to catch more errors (#9374) 2019-11-10 19:24:53 -08:00
package.json Switch all examples to next@latest (#7806) 2019-07-08 18:41:33 -04:00
README.md Add catch all routes example and a link to it in docs (#10202) 2020-01-27 13:29:05 -05:00

Dynamic Routing example

This example shows how to do dynamic routing in Next.js. It contains two dynamic routes:

  1. pages/post/[id]/index.js
    • e.g. matches /post/my-example (/post/:id)
  2. pages/post/[id]/[comment].js
    • e.g. matches /post/my-example/a-comment (/post/:id/:comment)

These routes are automatically matched by the server. You can use next/link as displayed in this example to route to these pages client side.

Deploy your own

Deploy the example using ZEIT Now:

Deploy with ZEIT Now

How to use

Using create-next-app

Execute create-next-app with npm or Yarn to bootstrap the example:

npm init next-app --example dynamic-routing dynamic-routing-app
# or
yarn create next-app --example dynamic-routing dynamic-routing-app

Download manually

Download the example:

curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/dynamic-routing
cd dynamic-routing

Install it and run:

npm install
npm run dev
# or
yarn
yarn dev

Deploy it to the cloud with Now (download):

now