Pages in next are all created under the /pages
directory. This directory contains both normal pages and api endpoints (api is accessible via /api
).
Pages and api endpoints both use next's file based routing feature and as such the path of the file corresponds to the path of the endpoint. E.g the file at pages/bob/fish.tsx
serves the page /bob/fish
.
These paths can also contain parameters by enclosing a file or folder name in []
e.g the file at /pages/bob/[fishName]/bait
will get served on a url of /pages/bob/perch/bait
and the value perch
will be put in the query variable fishName
.
It is important to note that next.js will try to create routes to every file in this directory and as such only files that are routes should be added to this directory or any of its sub-directories.
There are a couple of different ways a page can be rendered in next.js. See here for more information.