Moving & Organizing Routes — Let’s Learn Adonis 5, Lesson 2.2

Tom Gobich | Adocasts.com
4 min readSep 5, 2022

View all lessons in the Let’s Learn Adonis 5 series here.

Although Adonis starts our route definitions within our start directory within routes.ts, in actuality, it really doesn't care where our routes reside so long as we inform it where they're defined. In this lesson, we're going to cover a few options you have when it comes to structuring your route definitions.

As we go through this lesson it’s important to remember that keeping all your route definitions within the default routes.ts file is perfectly valid. In fact, that's what I do for most of my projects.

Routes Directory

One option we have is to group routes by topic and place them inside route-specific files inside a routes directory.

So, for a blog, we could have the following files within our routes directory.

  • /start/routes/auth.ts for all authentication routes
  • /start/routes/posts.ts for all post routes
  • /start/routes/topics.ts for all topic routes

We’d define the routes within these files the exact same as we would within our routes.ts file.

--

--

Tom Gobich | Adocasts.com
Tom Gobich | Adocasts.com

Written by Tom Gobich | Adocasts.com

Learn AdonisJS, NodeJS, JavaScript and more through in-depth lessons, screencasts, and livestreams at adocasts.com

No responses yet