named-react-router
Version:
A lightweight extension to React Router for named routes
31 lines (30 loc) • 1.05 kB
TypeScript
import { NavLinkProps } from 'react-router-dom';
import { JunctionTo } from '../index';
interface NamedNavLinkProps extends Omit<NavLinkProps, "to"> {
/**
* A wrapper component around react-router-dom's `NavLink` that enables named route navigation.
*
* It accepts either a direct path or a named navigation object that
* resolves named routes to their absolute paths, including parameters and query strings.
*
* @example
* ```tsx
* // Named route navigation with params and query
* <NamedNavLink
* to={{
* name: "searchResults",
* params: { category: "books" },
* query: { sort: "price", order: "asc", page: "2" }
* }}
* />
*
* // Direct path navigation
* <NamedNavLink to="/about" />
* ```
*
* @param to - Either a named route or a direct path as a string.
*/
to: JunctionTo;
}
export declare function NamedNavLink({ to, ...navLinkProps }: NamedNavLinkProps): import("react/jsx-runtime").JSX.Element;
export {};