From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Handling route wildcards

Handling route wildcards

In NestJS, route wildcards are placeholders within routes that match any combination of characters in that position of the URL. They are mainly denoted by an asterisk sign. This asterisk acts as a wildcard character, matching any combination of characters. For instance, in the route path, ab asterisk cd, the route path would match URLs like abcd, ab underscore cd, abecd and so on. So basically, the asterisk denotes any possibility. That's what a wildcard route is. Let's understand it by looking at an example. I am going to extend the content type example which we saw previously. In here, we will add a few more get handlers. I'll change the method name to route1 and we'll change the return message as well to this is route1 under slash client. So we will define a few routes like this. The whole purpose I want to explain is how to apply a middleware on multiple or all the child routes coming under a specific controller route. I will change the route path to route 2. Will update the…

Contents