Handling Routes in an Oak Application

Learn to create a router with Oak.

Creating a router

In this lesson, we will implement the functionality that will list all the museums from our application.

Let’s add it and learn how can we create routes in an Oak application.

Oak provides another object, alongside the Application class, that allows us to define routes—the Router class. We’ll use this to reimplement the route we had before, which listed all the museums in the application.

Let’s create it by sending the prefix property to the constructor. Doing this means that all the routes defined there will be prefixed with that path:

Get hands-on with 1200+ tech skills courses.