Route Middleware
Learn how to apply middleware and its different types.
We'll cover the following
Route middleware is a piece of code that we want to execute before navigating to a particular route, you can think of it as an extra stage to pass through before completion. It can be applied to all the routes in our app, or on particular routes. Use cases could include checking if a user is logged in before visiting a certain admin or account page and checking if a shopping basket contains items inside before visiting the checkout page. Let’s take a look at the types of route middleware.
Named middleware
Named middleware applies only to certain routes and is added to a directory called middleware
at the root of our project.
Get hands-on with 1400+ tech skills courses.