useLink
The hook resolves a path into a href from a route.
ts
import { useLink } from 'atomic-router-react';
Be sure, route is passed into routes
for createHistoryRouter
. Otherwise, the hook will throw [useLink] Route not found
.
Also, useLink
requires to be used inside a RouterProvider
.
Example
tsx
import { useLink } from 'atomic-router-react';
import { createRoute } from 'atomic-router';
// example path: /some/route/:someId
const someRoute = createRoute<{ someId: number }>();
function SomeComponent() {
const path = useLink(someRoute, { someId: 1 });
// -> /some/route/1
}