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'); });