UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

104 lines (52 loc) 1.66 kB
--- lang: en title: 'API docs: rest.restserver.redirect' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/rest permalink: /doc/en/lb4/apidocs.rest.restserver.redirect.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/rest](./rest.md) &gt; [RestServer](./rest.restserver.md) &gt; [redirect](./rest.restserver.redirect.md) ## RestServer.redirect() method Register a route redirecting callers to a different URL. **Signature:** ```typescript redirect(fromPath: string, toPathOrUrl: string, statusCode?: number): Binding; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> fromPath </td><td markdown="1"> string </td><td markdown="1"> URL path of the redirect endpoint </td></tr> <tr><td markdown="1"> toPathOrUrl </td><td markdown="1"> string </td><td markdown="1"> Location (URL path or full URL) where to redirect to. If your server is configured with a custom `basePath`<!-- -->, then the base path is prepended to the target location. </td></tr> <tr><td markdown="1"> statusCode </td><td markdown="1"> number </td><td markdown="1"> _(Optional)_ HTTP status code to respond with, defaults to 303 (See Other). </td></tr> </tbody></table> **Returns:** [Binding](./context.binding.md) ## Example ```ts server.redirect('/explorer', '/explorer/'); ```