The translation was generated automatically and may contain mistakes

RouteNavigator.replace

It performs a transition to a new URL, but does not add an entry to the transition history, but replaces the current one. Draws components corresponding to the new URL.

Example

TypeScript
import { useRouteNavigator } from '@vkontakte/vk-mini-apps-router'; export function SomePage() { const persikPanel = routes.default_root.default_view.persik_0; return ( <Button onClick={() => routeNavigator.replace( '/emotion-panel/:emotion', {emotion: 'fish' }, { keepSearchParams: true } ) } > Персик хочет кушать </Button> <Button onClick={() => routeNavigator.replace('/path', {keepSearchParams:true }) } > Персик хочет кушать </Button> <Button onClick={() => routeNavigator.replace({search: {fish: 'beluga'}}, hash: '12'}); } > Остаться на странице и изменить hash и search </Button> <Button onClick={() => routeNavigator.replace( { pathname: persikPanel, hash: '12' }, { emotion: 'sad' }, { keepSearchParams: true } ); } > Персик хочет кушать </Button> }

Parameters

Option 1

TypeScript
replace(to: string | Page | {pathname?: string | Page, hash?: string, search?: URLSearchParams | Record<string, string> | string}, options?: NavigationOptions): Promise<void>
Parameter
Type
Description
to Mandatory
End point for transition. You can choose one of three ways. Details in section NavigationTarget .
options optional
An auxiliary parameter used in navigation. If you set the parameter to pass {keepSearchParams: true} , то router save query parameters from the current URL when moving to a new address. With properties {state: {...}} Parameters can be passed in transition. Details in section Passing Parameters — Additional Method Parameters push() ?1? replace() .

Option 2

TypeScript
replace<T extends string>(to: PageWithParams<T> | {pathname: PageWithParams<T> | string, hash?: string, search?: URLSearchParams | Record<string, string> | string}, params: Params<T>, options?: NavigationOptions): Promise<void>
Parameter
Type
Description
T optional
object
An object that can be used to type parameters to ?1? params .
to Mandatory
End point for transition. You can choose one of three ways. Details in section NavigationTarget .
params Mandatory
object
An object whose fields contain values path-параметров indicated on the way. Path parameters can also be specified in to . Usage params It can be easier to code and easier to read. Details in section Path parameters .
options optional
An auxiliary parameter used in navigation. The same meaning as in Option 1 .

Result

Object Promise which is allowed if the transition is successful. Works for official purposes. Using this object in your code is usually unnecessary.

Materials on the topic