The translation was generated automatically and may contain mistakes

useHref

Use the function useHref(...) to get the address to go to your app screen. This address corresponds типу роутера in your application and can be used to create external links to the screen.

Route
Created Reference
/contacts/edit
Hash router :             /#/contacts/edit HashParam-роутер :  /#path=%2Fcontacts%2Fedit Browser-роутер :       /contacts/edit

The created link can be used in the attribute href Elements <a> и <Link> in your application. It can also be used to create an external link to the application screen. To do this, you need to add an application address to it, for example https://vk.com/app12345/#/contacts/edit .

Example

TypeScript
import { routes } from '../routes'; import { useHref, Link } from '@vkontake/vk-mini-apps-router'; const pageURL = useHref('/contacts/edit'); const pageWithParamsURL = useHref( routes.default_root.default_view.persik_0, { params: { emotion: `sad` } } ); <Link href={pageURL}>Edit Contacts</Link> <Link href={pageWithParamsURL}>Persik</Link>

Announcement

TypeScript
export function useHref(to: NavigationTarget, { relative }: { relative?: RelativeRoutingType} = {}): string

Parameters

Parameter
Type
Description
to Mandatory
End point for transition. You can choose one of three ways. Details in section NavigationTarget .
relative optional
object
Reserved for future use.
params optional
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 .

Result

The function returns a reference for the screen whose route is specified in the parameter NavigationTarget .

With the vk-mini-apps-router library, you can create routers different types . The function takes into account the type of router your application uses and returns the link in the correct format.

Features of use

Function calls useHref() should be included in the component RouterProvider .

Materials on the topic