Redirect Responses in NestJS
📖 Scenario: You are building a simple web server using NestJS. Sometimes, you want to send users to a different web page automatically. This is called a redirect. For example, when a user visits the home page, you want to send them to the welcome page.
🎯 Goal: Create a NestJS controller that redirects users from the root URL / to /welcome using the proper NestJS redirect response method.
📋 What You'll Learn
Create a controller class named
AppController.Add a method named
redirectToWelcome that handles GET requests to /.Use the
@Redirect decorator to redirect to /welcome with status code 302.Add a method named
welcome that handles GET requests to /welcome and returns a simple welcome message.💡 Why This Matters
🌍 Real World
Redirects are common in web apps to guide users to updated pages or login screens automatically.
💼 Career
Understanding redirects is important for backend developers working with web frameworks like NestJS to manage user navigation and HTTP responses.
Progress0 / 4 steps