⚡
light
  • light
  • guides
    • getting started
    • server vs serverless
    • routes
    • models
    • factories
    • routing
    • plugins
    • middleware
    • query
    • params
    • global
    • error handling
    • hot module reloading (TODO)
    • databases (TODO)
      • mongoose
      • objection/knex
    • testing (TODO)
      • ava
      • jest
    • deployments (TODO)
      • runkit
      • aws
      • now
      • heroku
      • server
      • google cloud
      • azure
      • netlify
    • misc (TODO)
      • apollo/graphql
  • api
    • server({ routes, opts }): object
    • params(path, url): Promise<object>
    • boom
      • Coming soon
    • micro
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
      • Coming soon
Powered by GitBook
On this page
  • Introduction
  • Automatic Routing

Was this helpful?

  1. guides

routing

PreviousfactoriesNextplugins

Last updated 5 years ago

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

Introduction

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.

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, .

server mode
find-my-way
detailed here