Questions & Answers

How can I perform redirects?

Deepkit HTTP
50 up-votes
Warning: The answer is generated by an artificial intelligence. It might not be correct.
To adjust rating, open the thread in Discord and click on the up/down vote button.

To perform redirects in Deepkit HTTP, you can use the Redirect class. There are two methods available: Redirect.toRoute and Redirect.toUrl.

For example, to perform a redirect to a specific route, you can use Redirect.toRoute along with the route name:

import { Redirect } from '@deepkit/http';

router.get({path: '/new-route', name: 'newRoute'}, () => {
  return 'Hello there';
});

router.get('/old-route', () => {
  return Redirect.toRoute('newRoute');
});

Alternatively, you can also perform a redirect to a specific URL using Redirect.toUrl:

import { Redirect } from '@deepkit/http';

router.get('/old-route', () => {
  return Redirect.toUrl('/new-url');
});