# routing

**Please note that routing is environment specific. The details documented below only apply to** [**server mode**](https://github.com/ludicrousxyz/light/tree/207804d2e826e1f45ff0c63ba7b17f61c563bd82/guides/server-vs-serverless/README.md#server) **since serverless environments will have their own custom routing**

## Introduction

Under the hood, light uses [find-my-way](https://github.com/delvedor/find-my-way) to route in server mode. find-my-way turned out to be one of the fastest routers available while allowing for advanced features such as hot module reloading. Reading the find-my-way documentation in conjunction with this guide may help you understand light's router better.

## Automatic Routing

When in server mode, if a `path` is not specified, light will try to guess the route based on its location in the directory. By default `routes/index.js` is treated as `/`, but other than that, it will use the system path. For example creating a file in `routes/posts/new.js` will yield the route `/posts/new` by default.

Additionally, to support dynamic urls such as `/users/:username`, simply create a file called `[username].js` in the `users` folder. You can then use the `useParams` function to extract the username, [detailed here](/guides/params.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.light.js.org/guides/routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
