The identifier for the entry point when the application uses the Pages
entry type.
Compatible with Modern.js 1.0 Pages
entry. It is recommended to use conventional routing.
When the project structure is of the Pages entry
type, the client-side routing configuration will be obtained by analyzing the files in the src/pages
directory.
For example, the following directory structure:
The corresponding generated routing configuration is:
Files under the pages directory that meet the following conditions will not be treated as routing files:
.(j|t)sx?
..d.ts
type definition files..test.(j|t)sx?
or .spec.(j|t)sx?
or .e2e.(j|t)sx?
.It is recommended to only write entry code in the pages directory and write business logic in the independent features directory outside the pages directory. In this way, most of the files under the pages directory will be routing files, and there is no need for additional filtering rules.
If the directory name of the route file is named with [], the generated route will be used as a dynamic route.
For example, the following directory structure:
The corresponding generated routing configuration is:
On the basis of dynamic routing, special routing suffixes (*, ?, +)
can be added.
For example: src/pages/users/[id]*.tsx
will result in the route /users/:id*
.
When the entire application needs a global layout
, it can be achieved through pages/_app.tsx
. The specific writing method is as follows:
The above Component
is the component matched when accessing a specific route.
For example, the following directory structure:
/
corresponds to the Component
component in pages/index.js
./a
corresponds to the Component
component in pages/a/index.js
./a/b
corresponds to the Component
component in pages/a/b/index.js
.When developing an application, there are scenarios where sub-routes under the same route share a layout.
For this scenario, Modern.js conventionally has a similar effect to global layout when there is _layout.js
under the directory.
For example, the following directory structure:
The Component
parameter is the component corresponding to a specific accessed route, for example:
/a
corresponds to the Component
component in pages/a/index.js
./a/b
corresponds to the Component
component in pages/a/b/index.js
.In this way, pages/a/_layout.js
can be used to meet the layout needs of shared routes under the a
directory.
pages/404.[tj]sx
is conventionally the default 404 route.
For example, the following directory structure:
The generated routing configuration is as follows:
All unmatched routes will be matched to pages/404.[tj]s
.