routing
Last updated
Was this helpful?
Last updated
Was this helpful?
Please note that routing is environment specific. The details documented below only apply to since serverless environments will have their own custom routing
Under the hood, light uses 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.
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, .