This document provides an overview of the routing mechanism in the Singularity framework. It explains how routes are automatically mapped to files and how to create new routes.
In the Singularity framework, routes are automatically mapped to files in the client
directory. This helps to prevent relative and absolute paths hell.
filename.ext
inside theclient
folder will be automatically served at/filename.ext
.filename.jsx
inside theclient
folder will be automatically rendered and served at/filename
.filename/filename.jsx
inside theclient
folder will be automatically rendered and served at/filename
.
This is to prevent index hell, where every file in your project is called index
. The framework enforces you to either have a filename.jsx
in the client
folder or filename/filename.jsx
. Any index.jsx
apart from the main client/index.jsx
will be ignored.
To create a new route, simply add a new file in the client
directory with the desired route name. For example:
- To create a route for
/about
, add a file namedabout.jsx
in theclient
directory. - To create a route for
/contact
, add a file namedcontact.jsx
in theclient
directory.
The framework will automatically map these files to the corresponding routes.
Dynamic routes are not yet supported in the Singularity framework. However, you can use normal API fetch for data fetching.
Nested routes are not yet supported in the Singularity framework. However, you can create nested directories in the client
folder to organize your files better.