-
Notifications
You must be signed in to change notification settings - Fork 0
Next.js API Routes
Next.js uses File System Routing where names of directories define the url structure of the web app.
In Next.js 13, the routes are defined in the /app
directory. In previous versions, they were defined in the /pages
directory. Massive.
Routes start after the /app
directory. For example a page located at /app/about.tsx
will be accessible at /about
and pages located at /app/Contact/Home/index.tsx
will be located at /Contact/Home
, etc.
When you don't know the exact name of the next segment in the route, or you want to parse extra parameters, we have Dynamic Routes to save the day.
To create a dynamic route, we wrap the name of your directory or page in [square brackets]. For example:
-
/app/shop/[shopName].tsx
->/shop/coffee
will have parameter 'coffee'
To include many parameters, we precede the name of the route with elipses ('...'). These are called 'Catch-all Segments'. Example:
-
/app/shops/[...shopNames]
->/shop/coffee/tea
will have parameters 'coffee' and 'tea'.