navigate
Reference
navigate(route: string, options?: { renderMode?: 'transition' | 'reactivity' | 'native' }): never
The navigate function is used for imperative navigation.
import { navigate } from "brisa";
// ...
navigate("/some-page");
The navigate function can be used both on the client and on the server. Although there are some differences to be taken into account:
- If the navigation is done before sending the response (in the middleware,
responseHeadersor an API endpoint for example), instead of modifying the navigation history it does a 301 redirect. - If it is done during rendering, SPA navigation or Server Action a soft redirect is made.
- If used inside a client-event or a server-event (action) a new page is always generated in the navigation history.
All i18n navigation rules apply equally in this function.
Parameters:
route: Thestringwith the page route name. Ex:/about-usoptions: Theobjectwith the navigation options. Ex:{ renderMode: 'transition' }renderMode: Thestringwith the render mode. Supported:'transition','reactivity','native'. (default:'reactivity'when the render mode is applicable, otherwise'native')
The usage of
renderModeis not applicable in the cases that use a hard redirect. Only is applicable in the cases that use a server soft redirect or execute a client-side navigation. Otherwise, always the native render mode is used.
Returns:
Neverdoes not require you to usereturn navigate('/some')due to using the TypeScriptnevertype.
Avoid using the
navigateinside atry/catchblock. Thenavigateis a throwable function and will break the execution of the current function.
Support
| Component | Support |
|---|---|
| Server Component | โ |
| Web Component | โ |
| SSR Web Component | โ |
| Actions | โ |
| Middleware | โ |
| Response headers | โ |